0
votes

I try move the object when I press 'A' button but it doesn't work. I tested with 'B' button and the object was moved. Why the rigidbody doesn't react on 'A' button?

if (Input.GetKeyDown(KeyCode.A))
            rigidbody.AddForce(new Vector3(-5, 0, 0), ForceMode.Impulse);
1
I can assure you, that you are using wrong tags. You want to use unity-3d tag, before someone downvotes you. - Paweł Mach
I find problem - I set rigidbody.Sleep() but obj still can't move by press 'A' and it move when I press 'D'. Why? - Станислав П
addforce for x movemenet is unnecesary. you can simply move it. add force is usefull for jumping or pushing objects and like that. - virtouso
ok, but I need use AddForce - Станислав П

1 Answers

0
votes

"W", "A", "S", "D" will not work as they're map in a default settings in Unity. Somewhere in the preference key mapping.

Now if you want to use "A". I believe it is Mapped as "Left" or "left" try both.

If you check here. http://docs.unity3d.com/ScriptReference/KeyCode.A.html

Using the code above is Correct. But they didn't inform anyone that you need to re map the controls first.

Now for some reason, this does not work for you. Then just use.

if (Input.GetKey(KeyCode.A))

Notice that there is no Down. Why does this work and GetKeyDown Doesn't?

Because WASD is tied up as Accel for Anolog purposes. So Down, will not work it reads from 0.0 to 1.0 Sadly for key board it goes from 0.0 to 1.0 but for controllers, you get different results depends when you press lightly or hard.