- Home /
"Hover Vehicle" Object with ProjectOnPlane has unintended rotation
Hello, I'm trying to create a hover vehicle racer, the vehicle can "stick" on surfaces and glide along them but it seems to tilt even when it is on a flat surface after moving it around on these surfaces for a bit, especially like the pipe that's on the background of the image, not sure why it's happening but I think it's caused somewhere along in the ProjectOnPlane that takes care of the vehicle's rotation (If you're wondering, the trackNormal is extracted from a raycastHit, bci is just a script that takes care of smoothing the normals for the vehicle's movement but this still happened even without it)
if (raycast.collider is TerrainCollider)
{
TerrainData ter = raycast.transform.GetComponent<Terrain>().terrainData;
trackNormal = ter.GetInterpolatedNormal(raycast.textureCoord2.x, raycast.textureCoord2.y);
}
else
{
trackNormal = bci.GetInterpolatedNormal(raycast);
}
Vector3 planeProj = Vector3.ProjectOnPlane(transform.forward, trackNormal);
Quaternion rot = Quaternion.LookRotation(planeProj, trackNormal);
rigidBody.MoveRotation(rot);
Your answer
Follow this Question
Related Questions
Rotate Player to Match Surface Normal While Still Maintaining Y Rotation 0 Answers
Vehicle keep on floor? 1 Answer
Get X normal of collider below object regardless of rotation 1 Answer
Why is my spherecast returning an incorrect hit on mesh collider? 1 Answer
hit.normal rotation problem, help please really confused 1 Answer