- Home /
Input for Character Movement
I'm making a game in which you move a basketball around (yes, wierd), but I don't know how to put in the input right. Here's what is supposed to move it forward.
if (Input.GetButton("Vertical") && rigidbody.velocity.magnitude < maxspeed){
rigidbody.AddForce (Input.GetAxis ("Mouse X")*speed/ratio, 0, Input.GetAxis("Mouse Y")*speed);
}
Anyone have a script for such a thing, or at least how to correct this? Thanks.
Answer by Peter G · Aug 19, 2010 at 01:10 AM
My first guess is that you set up the wrong input values. Your current script requires the player to be hitting either "w", "s" or the up and down arrows WHILE you are also moving the mouse up or down. That sounds like a lot to do. You probably want to change Mouse Y
to Vertical
Another minor details is that to rotate an object, you use AddTorque, not AddForce for the x component, which if you change it, will actually be the y component.
One other thing is that it can take quite a bit of force to get an object moving (Newton's laws. An object at rest wants to stay at rest) , so I might try setting your speed abnormally high just to make sure you are getting some movement.
I changed the $$anonymous$$ouse Y and AddForce, but now it's going left or right! How do I change that?