Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Wall = script.Parent
- local Debounce = false;
- function GetSurface(part, pos)
- local rel = part.CFrame:pointToObjectSpace(pos)
- print("relative vector" .. tostring(rel))
- --if math.abs(rel.X) < part.Size.X and math.abs(rel.Y) < part.Size.Y and math.abs(rel.Z) < part.Size.Z then
- if math.abs(rel.Z) > math.abs(rel.Y) and math.abs(rel.Z) > math.abs(rel.X) then
- if rel.Z > 0 then
- return Enum.NormalId.Back
- else
- return Enum.NormalId.Front
- end
- elseif math.abs(rel.Y) > math.abs(rel.Z) and math.abs(rel.Y) > math.abs(rel.X) then
- if rel.Y > 0 then
- return Enum.NormalId.Top
- else
- return Enum.NormalId.Bottom
- end
- elseif math.abs(rel.X) > math.abs(rel.Z) and math.abs(rel.X) > math.abs(rel.Y) then
- if rel.X > 0 then
- return Enum.NormalId.Right
- else
- return Enum.NormalId.Left
- end
- end
- end
- Wall.Touched:connect(function(Part)
- local Player = (Part.Parent) and (Game.Players:GetPlayerFromCharacter(Part.Parent)) or nil;
- if (Player) then
- if (not Debounce) then
- Debounce = true;
- -- Math for reflecting the vector
- local PCCFrame = Player.Character:GetModelCFrame();
- local SurfaceTouched = GetSurface(Wall, PCCFrame.p);
- local SurfaceObjectSpaceVector = Vector3.FromNormalId(SurfaceTouched);
- local SurfaceWorldSpaceVector = Wall.CFrame:vectorToWorldSpace(SurfaceObjectSpaceVector);
- local PosVector_v = PCCFrame:toObjectSpace(Wall.CFrame).p
- local PosVector_a = SurfaceWorldSpaceVector;
- local RefVector = PosVector_v - (((2 * PosVector_v:Dot(PosVector_a))/PosVector_v:Dot(PosVector_a)) * PosVector_a)
- local WorldSpaceRefVector = Wall.CFrame:vectorToWorldSpace(RefVector);
- print("Player touched the " .. tostring(SurfaceTouched) .. " surface.");
- Player.Character:MoveTo(RefVector);
- local ObjectSpace = Player.Character:GetModelCFrame():toObjectSpace(Wall.CFrame);
- wait(1)
- Debounce = false;
- end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement