Hi,
I have a basic vehicle with a rigidbody and four wheelcolliders. I want the vehicle to jump and I have always been setting the 'up' velocity directly to make the jump predictable. This has always worked in Unity 4, but since upgrading if you keep jumping in rapid succession the jump is very unstable. I have been outputting the rigidbody velocity to console after the jump and I am not getting the result I have set it too. Does anyone have any ideas what has changed in version 5 to cause this? I susspect it might have something to do with the wheelcolliders. I'm struggling to get them to perform the same as unity 4.
Thanks
Here is the jump code.
public void Jump(float jumpForce, bool isChangingLanes = false)
{
if (!IsGrounded())
return;
if (!IsHandcarOnJumpableSurface())
return;
_isGoingToJump = true;
_isChangingLanes = isChangingLanes;
var velocity = _rigidbody.velocity;
Debug.Log(string.Format("Pre Jump Velocity: {0}", _transform.InverseTransformDirection(velocity)));
PrepareHandcarForJump(velocity);
velocity += Vector3.up * jumpForce;
_rigidbody.velocity = velocity;
Debug.Log(string.Format("Post Jump Velocity: {0}", _transform.InverseTransformDirection(_rigidbody.velocity)));
}
private void PrepareHandcarForJump(Vector3 velocity)
{
velocity.y = 0;
var rotation = _transform.rotation.eulerAngles;
_transform.rotation = Quaternion.Euler(new Vector3(0f, rotation.y, 0f));
_rigidbody.angularVelocity = Vector3.zero;
}
↧