- Home /
How to lock a vehicle to a curve normal in two dimensions?
I realise that the question isn't a very good explanation so I've included a picture. I would like a vehicle (which is floating above the ground) to be locked to the curve of the ramp all the way around, and also to the yellow lines in order to stay perpendicular to the centre of the circle of which the ramp is the radius.
I've kind of fixed the first part with this code from another thread:
RaycastHit hit;
if
(Physics.Raycast(transform.position, -curNormal, out hit)){
curNormal = Vector3.Lerp(curNormal, hit.normal, 4*Time.deltaTime);
Quaternion grndTilt = Quaternion.FromToRotation(Vector3.up, curNormal);
transform.rotation = grndTilt * Quaternion.Euler(0, curDir, 0);
I tried to fix the issue with this code but it hasn't worked:
Vector3 fromCentre = new
Vector3(34.16f, 23.05f, 60.66f);
Vector3 centreToShip = (transform.position - fromCentre);
Vector3 shipNormal = (hit.normal);
Debug.Log(shipNormal);
//matches vehicle to normal of ramp (vertical)
curNormal = Vector3.Lerp(curNormal, shipNormal, Time.deltaTime);
Quaternion grndTilt = Quaternion.FromToRotation(Vector3.up, curNormal);
transform.rotation = grndTilt;
I would really appreciate any help or direction with this.
Can you pls clarify: Do you want to create a scripted animation along the road and calculate the vehicles position, rotation and speed or are you working on a vehicle-controller and want to calculate the next position on the track according to some user-input?
Answer by misun1191 · May 29, 2020 at 04:09 PM
I'm also searching answers for the same question. I haven't found a definite answer, but this thread contains lots of helpful comments. https://forum.unity.com/threads/how-in-the-world-were-the-physics-in-f-zero-x-done.204747/?_ga=2.122614923.1056452554.1590671745-1716890399.1557168250
Your answer
Follow this Question
Related Questions
Problem with converting RaycastHit to Vector3 2 Answers
Raycasts in opposite directions only returning RaycastHits on right 1 Answer
Offsetting Raycasting 1 Answer
Relative Rotation 1 Answer