- Home /
Adding forces with input.getaxis
I am trying to add force to an object with input.getaxis but it does not seem to work for some reason. If I try to translate an object using the same method it seems to work, but how would I go about adding forces? Right now my object does not move at all.
Code:
var moveSpeed : float = 10.0;
function FixedUpdate () {
var translation : float = Input.GetAxis ("Vertical") * moveSpeed;
translation *= Time.deltaTime;
rigidbody.AddRelativeForce (0, 0, translation);
}
I can't seem to grasp what I am doing wrong since translating an object with the same method worked.
Answer by GameVortex · Dec 06, 2013 at 11:33 AM
For forces you should not multiply in Time.DeltaTime, that value is usually very small (less than 0.05f, depending on framerate) and phycics already takes the framerate into account. GetAxis can be max 1.0f and movespeed is 10. TotalForce = 1.0f 10.0f 0.05f = 0.5f. That is too small amount of force to be able to move a rigidbody (if the mass is 1).
Remove the "translation *= Time.deltaTime;" and it should work better, you can also try increasing movespeed a little.
Your answer
Follow this Question
Related Questions
adding force to instantiated ragdoll 4 Answers
stop adding force 2 Answers
Shoot player away after loading force. 1 Answer
RigidbodyFirstPersonController and external forces... 0 Answers
How do you use Add.Force() to fly in the mouse-inputted direction? 0 Answers