- Home /
Moving Up, Down, Left and Right via Wasd and the arrow btns?? in 2d
I just want to move the object via wasd or arrow btns like in space invader! 2D! How to do it? Javascript pls! if script examples are getting used!!
should work sumhow like that??
if (Input.GetButtonDown ("Jump")) {
rigidbody.velocity = Vector3(0,10,0);
}
only for my wasd!
Celofa
haha yeah i know!! it wasnt about the tag!! i mean the way to move object!! I would have to rename the inputs for my needs!
Answer by Meater6 · Jan 17, 2011 at 04:33 PM
I made a cube fly around like a spaceship with this script:
function FixedUpdate()
{rigidbody.velocity = Vector3(
Input.GetAxis("Horizontal") * speed,
Input.GetAxis("Vertical") * speed,
0,
);
}
This makes the spaceship fly around on the xy plane. You may need to change the speed depending on the mass of the spaceship. Also, make sure the the Horizontal and Vertical axes are set to wasd keys and the rigidbody is not affected by gravity.
I hope this helps.
Whoops... No comma after the zero. $$anonymous$$ake sure you fix that.
Answer by Jesse Anders · Jan 17, 2011 at 04:53 AM
If you want to move the object using applied forces, it might look something like this (untested):
function FixedUpdate()
{
rigidbody.AddForce(
Input.GetAxis("Horizontal") * forceMagnitude,
Input.GetAxis("Vertical") * forceMagnitude,
0
);
}
But if i want one player with WASD and another player with Arrow ! how i can do ?