Need help with collision detection

Hello!

So I want a smooth collision system for my fighting game that can get position and the surface normal properly and accurately.

The problem is, that to get the surface normal and hit position of a part, you have to use a raycast, but the whole reason I want to get the surface normal and hit position is so that I can rotate my part to face the wall to cast an accurate ray. I’ve looked around on youtube and the devforum to no avail, hence the post.

Anyway, since this is really hard to explain in words heres some pictures to explain:

https://gyazo.com/d047d3c69d2e9c95bf58370965ac61c7
btw what I need is the collision point and the surface normal.

Thanks for any help in advance! :sweat_smile:

Well if you are trying to get a surface normal of a wall, and the wall is just a part, then all you need to do to get the surface normal is check the lookVector of that wall.

What? No I need to find what face of the wall that the player is touching…

Are we assuming the player is touching the wall? What is all the data that we know…

Yes the player has been knocked back and the script has already detected that the player is touching the wall, what I need is the point where the player’s hitbox and the wall intersects, if that is even possible… :confused:

1 Like

I’m not to sure if its possible, and if it is that I can figure it out :stuck_out_tongue: tbh. I’ll try to see if I can find a way but no guarantee

Ok so apparently I figured it out, I didn’t even need to find the collision point or anything, all I needed was to add this after the collision -

code:

local normal = thismod.getSurface(char.HumanoidRootPart.Position,collided)
	normal = collided.CFrame * Vector3.FromNormalId(normal) - collided.Position
	local hitpos = char.HumanoidRootPart.Position
	local rotcframe = CFrame.new(hitpos, hitpos + normal)	
	char:SetPrimaryPartCFrame(rotcframe)

getsurface function:

local surfaces = {
		back = object.CFrame * CFrame.new(0, 0, object.Size.Z);
		front = object.CFrame * CFrame.new(0, 0, -object.Size.Z);
		top = object.CFrame * CFrame.new(0, object.Size.Y, 0);
		bottom = object.CFrame * CFrame.new(0, -object.Size.Y, 0);
		right = object.CFrame * CFrame.new(object.Size.X, 0, 0);
		left = object.CFrame * CFrame.new(-object.Size.X, 0, 0);
	}
	local surface = "back"
	for side, cframe in pairs(surfaces) do
		surface = ((position - cframe.p).magnitude > (position - surfaces[surface].p).magnitude and surface or side)
	end
	return surface

Yeah so no complicated raycasts or anything! yay! Also, here is the result…

https://gyazo.com/0d4e7bcdb02268dafd0ceebb4f8cc1b3
(Note that the teleportation at the end was for debugging purposes and is not part of this code)