Quantcast
Channel: Answers by "Matt-Downey"
Viewing all articles
Browse latest Browse all 90

Answer by Matt-Downey

$
0
0
I really dislike both of the methods because they get really whacky at larger angles, which prompted me to invent a new method a while back. Since then I've made two methods that should be better or faster or both... //This first equation only works for gravity being downward (so it's perfect for first person shooter) //it is both faster and it is infinitely accurate according to my interpretation of how movement on slopes should work in first person shooter: //planar equation: ax + by + cz + d = 0 //(a,b,c) = slope of the plane or the magnitude of normal vector's components //"d" is zero because of our coordinate system. //(x,y,z) is partially known, we know x is vect.x and z is vect.z y = (-normal.x*vect.x - normal.z*vect.z)/normal.y; //find "y" by y = (-ax - cz)/b direction = Vector3(vect.x,y,vect.z); direction.Normalize(); //The second works easily on floors, walls, and ceilings (although with the normalization it should be more expensive than two cross products), so gravity could theoretically be in any direction //This method is slower and is less accurate at steep angles compared to the previous code, but it took me three months to notice it was off its mark and if its any consolation and it's infinitely better than the aforementioned (google + other) methods on steep slopes: //By dot product/negative inverse, this is orthogonal to the normal var right : Vector3 = Vector3(normal.y,-normal.x,0); //in world space var forward : Vector3 = Vector3(0,-normal.z,normal.y); //in world space right.Normalize(); forward.Normalize(); //the direction the player will move (tangential), which is a combination of any two non-parallel vectors on the correct plane var direction : Vector3; direction = right*vect.x + forward*vect.z; direction.Normalize();

Viewing all articles
Browse latest Browse all 90

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>