Hello,
I’ve made script so that the player object can me moved with the arrow keys, but when I press right or left the player is not only going right or left but also a little bit forward(in the z-axis). This is my move script:
void FixedUpdate () {
if(isGrounded){
input = new Vector3(Input.GetAxis ("Horizontal"), 0, Input.GetAxis("Vertical"));
if(rigidbody.velocity.magnitude < maxSpeed){
rigidbody.AddRelativeForce(input * moveSpeed);
}
}
}
When I set the gravity in the rigidbody in the inspector off, it isn’t happening anymore. But then I have no gravity. Is it better to use the character controller and set a gravityY variable so the player object can fall?
How is it possible that the object is also going forward, and how can I prevent this?