Help with Controlling Character...assigning movement keys

I’m not a programmer…so I don’t really know what I’m doing, but I’ll try to explain what I hope to achieve.

This is for a character controller and basically I’ve been trying to get my character to:

- Move forward/backward when w/s are pressed.
- Strafe left/right when a/d are pressed.
- And Rotate left/right when both wa/wd are pressed.

However, once again…I know nothing of Java/C# :frowning:

But I do know that to assign something to the “spacebar” I type:

if(Input.GetButtonDown(“Jump”))
{

}

Is it something similar?

Thanks for any help! :slight_smile:

you can either use the input manager edit - project settings - input there you can define “axis” like the “jump” in your example. it allows for advanced features and can map several key to the same axis.

if you are sure you will always have the same inputkeys you can also use keycode: Unity - Scripting API: KeyCode
this way you can query all keys and have complicated setups like you want.

note: i’m not sure how your approach conflicts with the character controller. i think there you also configure the keys for movement but have never worked with it.

and unity does not use java but unity script which is a dialect of java script (which has nothing to do with java).

Awesome! I read the post below me:
http://forum.unity3d.com/threads/107596-Is-Animation-Blending-just-can-have-2-animations

And used:
if(Input.GetKeyDown(KeyCode.A))
{
transform.Rotate(0, Input.GetAxis (“Horizontal”) * rotateSpeed, 0);
}

To rotate my character, but the problem is that I have to repeatedly tap the “A” key for it to work. Is there a way for it to work fluidly when I just hold the “A” key down?

Thanks!

Wow, thanks for the link! It’s still “choppy” when I have to keep tapping the buttons, but I think I’ll try that and see if it works. :slight_smile:

Ok, to strafe left I made this script:

//Move left
if(Input.GetKeyDown(KeyCode.A))
{
var left = transform.TransformDirection(Vector3.left);
var strafeLeft = speed * Input.GetAxis (“Horizontal”);
controller.SimpleMove(left * strafeLeft);
}

But I only move left 1 tiny pixel each time I press the button…:frowning:

Unity - Scripting API: Input.GetKey is what you need.

define a speed variable and set it to higher value.
also let you output the values getkey returns (for testing). the mousewheel can return 0.1 for example.
and you should multiply the value also with time.deltatime to be frame rate independant.

Perfecto! Sorry for all the posts! Thank you very much!
Goes back to designing game :slight_smile:

In the beginning I had the same problem, but parallel to my research on the forums I watched the tutorial series of Brackeys(https://www.youtube.com/playlist?list=PLPV2KyIb3jR5QFsefuO2RlAgWEz6EvVi6)

To fix the problem use <if ( Input.GetKey(“w”) )>
instead of <if(Input.GetKeyDown(KeyCode.A))>