Ninja code

Top  Previous  Next

Almost every week I receive emails from people who ask something like this: how can I add jumping to my movement code? Or do you happen to have a good movement / camera code snippet? Well, there you have it: movement code, camera code, jumping code and wall climbing code in a single, cholesterol-free package!

 

aum56_ninja1

 

Use the mouse and the cursor keys or WSAD to move and rotate the player. Press "space" or the right mouse button to jump. Move towards a wall, and then press and hold the "Ctrl" key (without releasing the forward movement key) to climb up a wall that's in front of the player, closer than 20 quants to the player. Release "Ctrl" at any time to fall down.

 

If you aren't that much of a programmer, you will be happy to hear that the code is highly customizable; just right click the player entity, choose "Behavior" and you will see the following window.

 

aum56_ninja2

 

Most of the options are self-explanatory, so you shouldn't have any problem with them. I'll list them and their role right here anyway:

- Health = player's health (default = 100);

- Camera height = distance between player's origin and the camera on the z axis (default = 50 quants);

- Camera distance = distance between the player and the camera (default = 250 quants);

- Player speed = player's movement speed (default = 6);

- Player inertia = player's inertia (default = 0.5);

- Player rotation speed = player's pan angle rotation speed (default = 5);

- Player climbing speed = player's vertical speed while it is climbing walls (default = 5);

- Dist to ground = distance to ground, tweak it until player's feet sit perfectly on the ground (default = 6 quants);

- Pan rotation speed = the speed with which the camera follows player's orientation (default = 0.8);

- Tilt rotation speed = the speed with which the camera can be tilted (default = 7);

- Foot step distance = the distance between two consecutive foot step sounds (default = 59 quants).

 

If you are a brave guy or girl, you will want to look at my heavily commented code and play with some of the settings. Btw, I have used an animation that makes the player appear to be using its sword for climbing; if you have a different "climb" animation feel free to use that instead.

 

I have included a full demo that shows the player in action, but here's how you can add this piece of code to your own projects:

1) Include the player.wdl code in your main script file;

2) Place a player model in your level, and then attach it the action named "my_player". That's all!