Rigidbody AddForce() stops working after walking away for a while
Hey, I'm having a really annoying problem and I have no clue how to even try to figure it out. I'm moving my character through AddForce() in it's Rigidbody. Here's how the character was set up:
the mind is an empty GameObject holding a script called Controller.cs, which controls the character through Keyboard+Mouse input. The Body contains Body.cs script, which moves the body with AddForce(). It also contains a capsule collider, to collide the body against ground, objects, etc...
Here is the movement script in Body.cs:
public void MoveInDirection(Vector3 direction, float intensity = 0.7f)
{
if (!canMove) return;
if (direction.magnitude != 1f) direction = direction.normalized;
body.AddForce(direction * intensity * maxLegForce);
//body.GetComponent<Rigidbody>().MovePosition(direction);
Debug.Log(body.velocity.ToString());
}
And here is the input script, in Controller.cs:
private void MoveInput()
{
Vector3 moveDir = Vector3.zero;
Vector3 forward = Vector3.forward; //bodyControl.transform.forward;
Vector3 right = Vector3.right; //bodyControl.transform.right;
// Eixo Z ( Forward )
if (Input.GetKey(KeyCode.W)) moveDir += forward;
else if (Input.GetKey(KeyCode.S)) moveDir -= forward;
// Eixo X ( Right )
if (Input.GetKey(KeyCode.A)) moveDir -= right;
else if (Input.GetKey(KeyCode.D)) moveDir += right;
if(moveDir != Vector3.zero)
{
bodyControl.MoveInDirection(moveDir);
}
}
And here is how it all acts up: link text
As you can see on the gif provided above, the character just starts slowing down, and stops. After that, AddForce() still applies force, but it does no effect to the position or velocity. any help would be greatly appreciated! Thanks in advance