Tuesday 26 November 2013

First code in UDK

I finally started writing code for UDK, the first few lines being a simple light switch.

Adding a trigger


That green volume represents where the player needs to be in order to use the switch. The light used has to be a toggle able light, you can find it in actor classes. The trigger can also be found in the actor classes menu.
Then i changed the properties of the trigger.

With the trigger selected, open Kismet and right click to add two events. One "Touch" to output the instruction ("Press E to turn light on/off") and a "Used" to toggle the light. I also needed a toggle able light object to link it to the toggle instruction. The instigator is who can activate the instruction, player 0 is 

Light switch code
With the code finished, you can hold Ctrl+Alt+click and drag around the code and press C to add a comment and make the code tidier.

The next challenge was to add a door and creating a little animation for it to open. First I found the static mesh of a door in the content browser, but I added it to the level as an InterpActor, because static meshes don't move! Then added a touch trigger in front of the stairs to activate it.

Door trigger

On the code part, I added an touch event and an Matinee code. With the Matinee code added I opened the Matinee screen (icon next to Kismet). With the door selected, right click and add an empty group, then, with the door still selected, right click again and choose "New Movement Animation". 

Matinee sequence

On the timeline press "Enter" to add a "Key Movement" and adjust how long you want it to last. Select the last key movement and move the door to its final position. Notice the thin string that will appear showing the path followed by the animation.

Door opening animation

The final code should something like this:
Final code




No comments :

Post a Comment