Hey everyone,
I have been having a problem with movement of a sphere; the speed is doubled when moving in a diagonal direction (WASD). I have read up on this and the issues stems from the force being applied twice when the 2 directions are pressed, ie. W +D.
The information I have come across suggests using .Normailze.
However I have added this to my code and there has been no resolution. Could anybody give me any advice?
public float maxSpeed = 5f;
public float Speed;
private Rigidbody rb;
void Start ()
{
spawn = transform.position;
rb = GetComponent<Rigidbody>();
}
Vector3 direction = new Vector3(0, 0, 0);
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
direction.Normalize();
if (rb.velocity.magnitude < maxSpeed)
{
rb.AddForce(movement * Speed);
}
Thanks for Reading, any help would be appreciated