- Home /
Strange Rigidbody Behavior
Hello everyone, I've noticed a strange behavior from a rigidbody movement script I have created. Essentially, when the rigidbody is moving at certain angles, the rigidbody will begin to drift away from its intended line of travel (even when floating with no gravity. The example picture shows the approximate line of travel, beginning along the rectangle's angle (160 degrees) and then drifting along a sloped path away from the wall as time goes on. Note that this does not occur when moving North, South, East, or West (or seemingly even nw,ne,sw,se), and that the rigidbody always continues to move forward (it just begins to drift).
I've tracked the line of code that makes this happen down to:
if (speedClamp) //player can move in x and z axis only,
{
playerVector.z = Mathf.Clamp (playerVector.z, -playerMaxForwardSpeed, playerMaxForwardSpeed);
Debug.Log ("playerVector.z is: " + playerVector.z);
playerVector.x = Mathf.Clamp (playerVector.x, -playerMaxForwardSpeed, playerMaxForwardSpeed);
Debug.Log ("playerVector.x is: " + playerVector.x);
}
If: playerVector.x = Mathf.Clamp (playerVector.x, -playerMaxForwardSpeed, playerMaxForwardSpeed); is commented out, the rigidbody moves correctly (never drifting away from its intended path), while the line for playerVector.z does not prevent the rigidbody from moving properly.
I'm quite confused as to why this is occurring, so if anyone has an idea, I would be grateful to know about it.
What method do you use to actually move the object?
Also, I've often experienced issues with jitter and path problem trying to move a box collider with rigidbody if there are any inclines.
I'm changing the rigidbody velocity directly (I know the manual includes a caution about this, but I'm not looking for true realism and I'm getting the behavior I want out of it).
I actually think I've just about got this figured out (I hope because I'm up way to late at this point), its just another simple error I missed because I was looking for a complex answer -> Depending on the direction of travel, the X or Z direction would max out, but the lesser value would just continue to increase (hence the weird drifting). Now, when one of the values max out, the smaller value stops growing, problem solved.
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Force to Velocity scaling? 2 Answers
RigidBody Script Conflict 1 Answer
Camera Following Rigidbody 0 Answers
Rigidbody Not Sliding Down Slopes 0 Answers