[SOLVED] Align model to normal

I’m trying to align a model via a normal.
Example:
IMG_20210820_211620
I want the car model to be inclined with the slope.

I’m firing a raycast below the car and I’m getting the normal, but I can’t figure out how to align the car using that normal.

I tried implementing this script:

But im getting a few NaNs in the Mat4 returned from setMat4Forward.

I have got the above script to work. I rounded off my values before passing them to the function and it started working. However I still haven’t reached the desired effect. Using this method, I can no longer control the turn direction of the car as it’s rotation is now controlled by the script. I need to think of a way to align it the normal, while still maintaing look direction.

I’ll try to see if this works:
https://answers.unity.com/questions/1732431/aligning-player-to-surface-while-still-maintaining.html

You may want try rotating the car on the local axis after it has been aligned to the normal?

1 Like