- Home /
Question by
me136703 · Jun 19, 2020 at 12:48 PM ·
physicsbugquaternionbug-perhapsvehicle
vehicle falls off loop (possible physics bug?)
Not a great title but I can't think of a good way to describe this problem, so there's a video of it here:
Basically whenever the vehicle reaches a point near the top of the loop, it falls off and sort of teleports to the ground below.
I've done some testing and can't find the cause of the problem: I rebuilt the environment in another scene and it worked fine, with the exact same code to be run on the loop:
RaycastHit hit;
Physics.Raycast(transform.position, -transform.up, out hit);
Vector3 forwardDir = Vector3.Cross(transform.right, hit.normal);
Quaternion newLook = Quaternion.LookRotation(forwardDir, hit.normal);
transform.rotation = Quaternion.Slerp(transform.rotation, newLook, 0.05f);
if (Physics.Raycast(transform.position, -hit.normal, 0.3f))
{
//rb.AddForce(hit.normal * 4, ForceMode.Acceleration);
}
else
{
//rb.AddForce(-hit.normal * 25, ForceMode.Acceleration);
}
(There is other code for the player to move while on the loop). Does anyone know why this could be happening or has anyone experienced something similar in the past?
(I asked this last week but accidentally put it in the help room and it predictably got buried)
Comment