x


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

more ▼

asked Jan 17 '11 at 02:51 AM

Celofa gravatar image

Celofa
82 15 15 24

I don't think it would use the "Jump" tag.

Jan 17 '11 at 03:00 AM Keavon

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!

Jan 17 '11 at 03:06 AM Celofa
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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.

more ▼

answered Jan 17 '11 at 04:33 PM

Meater6 gravatar image

Meater6
1.3k 10 14 27

Whoops... No comma after the zero. Make sure you fix that.

Jan 17 '11 at 04:35 PM Meater6
(comments are locked)
10|3000 characters needed characters left

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
    );
}
more ▼

answered Jan 17 '11 at 04:53 AM

Jesse Anders gravatar image

Jesse Anders
7.3k 7 17 48

But if i want one player with WASD and another player with Arrow ! how i can do ?

Dec 01 '12 at 06:54 PM ProXenT
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1425
x1071
x186
x37
x2

asked: Jan 17 '11 at 02:51 AM

Seen: 3228 times

Last Updated: Dec 01 '12 at 06:54 PM