- Home /
Removing velocity relative to the contact normal
Having an issue with a fast moving object going through the track; at the moment the track is detected using Raycasts and uses this information to position itself ontop of the track and oriented correctly (wipeout style game).
It's a classically case of object move increments being greater than the area being checked - I have moved the colliders higher which has helped a little. The problem is specific to hitting corners or tilted track segments.
The 2 solutions I have are:
1) Shoot rays from the bottom; if nothing is detected then shoot rays in the opposite direction (having performance issues at the moment so not wanting to go down this route).
2) Remove the velocity relative to the contact normal (or transfer that velocity to the facing direction or perpendicular to the track) - this is the approach I would like to take but not 100% sure how I can remove the this velocity. I have multiplied the -velocity by the normal and added this current velocity but this is (obvious that know what they're doing) not the right approach.
I noticed that the CharacterController's Move method is capable of 'sliding' the object along a collider - anyone know how the team at Unity would have implemented this?
Cheers
Answer by Josh 5 · Jun 16, 2010 at 01:28 AM
This appears to have worked for me...
velocity -= Vector3.Project( velocity, trackContactNormal );
Where velocity is the (obviously) objects current velocity (done manually because I needed something similar to the CharacterController but specific to a vehicle of sorts) and trackContactNormal is the contact normal from the RaycastHit object.
Has stopped me falling through the track when moving at pace; it is possible to transfer this velocity to the forward direction but I have decided not too to save some processing time.
Your answer
Follow this Question
Related Questions
Trying to avoid collision with sides and interiors of polygons 1 Answer
CharacterController collision disabled when modifying center 0 Answers
(Steam VR / Vive) Rigidbody moving in only one direction after collision 1 Answer
Double collision with Character Controller? 3 Answers
Voxel engine physics 3rd person character controller 1 Answer