Hey guys, so I’ve been trying to figure out how to implement ground hugging.
Which is basically having the player model’s down vector always facing the ground.
I’ve been trying to do it using the entity’s lookAt function gathering the ground normal etc but I haven’t been able to correctly do this.
In Unity, I’ve made it several times using Quaternion.LookRotation and making a Cross product but I don’t know what would be the equivalent in PlayCanvas.
Here’s a few very poor 2D illustrations of what I’m trying to do;
If you have the normal of the ground you want to hug, you can create the forward vector along the surface by cross producting the surface normal and the vehicle’s right vector. (You might have to do it the other way round as positive Z is ‘backwards’ in PlayCanvas)
Once you have the new forward vector, you can use the code from this thread to re-orientate the vehicle.