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:
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.
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…
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…