default movement problem
I have a problem with all my projects that whenever i attach a rigid body to an object and add an script for it to move,even something as simple as this
public float speed;
private Rigidbody agent;
void Start()
{
agent = GetComponent<Rigidbody>();
}
void FixedUpdate()
{
float H = Input.GetAxis("Horizontal");
float V = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(H, 0, V);
agent.AddForce(movement * speed);
}
the rigidbody starts moving without any input from my side and that in a direction b/w horizontal and vertical. Is there a cache or temp file i need to fix or what? I just need to know because this is happening to ever single project i start. Every single package i import,the object by default,without any input from me starts moving.
Answer by HenryStrattonFW · Nov 09, 2015 at 02:10 PM
Try logging out the values of H and V to ensure that they are as expected (0). And be wary of any controllers with joysticks you have connected, I've often had these axis return odd values because the joystick on my controller had something resting on it and was thus providing input.
Also just to cover it, if your agent is always moving downwards, make sure there is a valid floor underneath them for them to collide with.
I found out that without any input from my side, H & V are taking default values =1 in each case. How do i reset it ?
http://answers.unity3d.com/questions/303708/inputgetaxishorizontal-problem.html found out from this that my virtual joystick was the problem. Uninstalled it and the problem is fixed now. :D Thank you anyways :)
No worries, glad to hear you managed to resolve the issue.
Your answer
