I am trying to handle gravitational effect on my player project (while on an inclined plane) without using a dedicated Physics engine.
The reason behind my decision has something to do with the issues I encountered while trying to use Cannon JS.
I am now using moveWithCollisions to avoid walking through solid objects (that have checkCollisions set to true). However, that will also result in my player slowly sliding down any inclined plane while standing still.
My plan is to use Ray cast every frame to detect any ground underneath the player.
If none is detected, the player will “fall”.
If ground is detected, I want to find the angle of incidence of the ray with the intercepting mesh. If the angle is lesser than a certain limit (say 15 degrees), my player won’t slide (I’ll set the gravity vector for that frame to 0).
Problem is that I cannot seem to find out the angle of incidence (angle at which the ray hits mesh) during ray cast hit. Googling did not help.
Can someone please guide me in this regard?
Also, what do you think of my plan to fake the physics part in this manner?
I’d take the dot product of up axis and face nomal. If it’s below some value (maybe .9?) then do what you need to do with gravity.
The plan is worth a try. I’ve done something similar, but I use oimo and apply a force toward the ground (negative ground normal). I also added some custom code to oimo so that I don’t have to use a ray (I’m not using bjs physics plugin).