Advertisement
StefanBashkir

Untitled

Mar 5th, 2015
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. local Wall = script.Parent
  2. local Debounce = false;
  3.  
  4. function GetSurface(part, pos)
  5. local rel = part.CFrame:pointToObjectSpace(pos)
  6. print("relative vector" .. tostring(rel))
  7. --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
  8. if math.abs(rel.Z) > math.abs(rel.Y) and math.abs(rel.Z) > math.abs(rel.X) then
  9. if rel.Z > 0 then
  10. return Enum.NormalId.Back
  11. else
  12. return Enum.NormalId.Front
  13. end
  14. elseif math.abs(rel.Y) > math.abs(rel.Z) and math.abs(rel.Y) > math.abs(rel.X) then
  15. if rel.Y > 0 then
  16. return Enum.NormalId.Top
  17. else
  18. return Enum.NormalId.Bottom
  19. end
  20. elseif math.abs(rel.X) > math.abs(rel.Z) and math.abs(rel.X) > math.abs(rel.Y) then
  21. if rel.X > 0 then
  22. return Enum.NormalId.Right
  23. else
  24. return Enum.NormalId.Left
  25. end
  26. end
  27. end
  28.  
  29. Wall.Touched:connect(function(Part)
  30. local Player = (Part.Parent) and (Game.Players:GetPlayerFromCharacter(Part.Parent)) or nil;
  31. if (Player) then
  32. if (not Debounce) then
  33. Debounce = true;
  34.  
  35. -- Math for reflecting the vector
  36. local PCCFrame = Player.Character:GetModelCFrame();
  37. local SurfaceTouched = GetSurface(Wall, PCCFrame.p);
  38. local SurfaceObjectSpaceVector = Vector3.FromNormalId(SurfaceTouched);
  39. local SurfaceWorldSpaceVector = Wall.CFrame:vectorToWorldSpace(SurfaceObjectSpaceVector);
  40. local PosVector_v = PCCFrame:toObjectSpace(Wall.CFrame).p
  41. local PosVector_a = SurfaceWorldSpaceVector;
  42. local RefVector = PosVector_v - (((2 * PosVector_v:Dot(PosVector_a))/PosVector_v:Dot(PosVector_a)) * PosVector_a)
  43. local WorldSpaceRefVector = Wall.CFrame:vectorToWorldSpace(RefVector);
  44. print("Player touched the " .. tostring(SurfaceTouched) .. " surface.");
  45. Player.Character:MoveTo(RefVector);
  46. local ObjectSpace = Player.Character:GetModelCFrame():toObjectSpace(Wall.CFrame);
  47. wait(1)
  48. Debounce = false;
  49. end
  50. end
  51. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement