Collision Detection Help

Hey, I made a Quake I style movement system and I’ve stumbled upon something that I’m really bad with. One of those things being collision detection and flattening a vector against a wall (at least I think that’s what it’s called). By flattening a vector against a wall I mean this:

and right now this happens in my movement system:

I would want to know how I would detect if a wall is in front of the player and flatten the vector against it like shown in the GMOD example.

What I mean by flattening the vector against the wall on an image:

I would greatly appreciate snippets of code, videos, websites or anything really that would help me understand this :slightly_smiling_face:

(I am using the Linear Velocity body mover with a Vector Velocity Constraint Mode, ForceLimitMode is PerAxis and MaxAxesForce is Vector3.new(math.huge, 0, math.huge) )

Sorry for the bad handwriting on the image , it’s hard to write on PC.

1 Like

I don’t know the best way to implement this using Roblox’s API, but I can tell you the math for calculating the “flattened” vector. Based on the drawing you made, you already know your velocity vector v. If you can get the normal vector n of the surface you are colliding with then you can calculate the “flattened” vector f = v - (v dot n)n.

(v dot n)n will give you the component of v parallel with n going in the opposite direction. From there, we can subtract it from the original vector to get the component of v that is perpendicular to n and in the direction of v. I’ve drawn a picture that can hopefully illustrate what I mean. The dotted lines are just the vectors shifted so that the origins are the same as the normal vector (It makes the illustration easier to understand).

2 Likes

Thanks, I’ll probably try this method in a few days when I’m free.