Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.98 KB | None | 0 0
  1. local Mouse = game.Players.LocalPlayer:GetMouse()
  2. local Visual = workspace.TestModel
  3. local Hitbox = Visual.Hitbox
  4.  
  5.  
  6. function RoundByThree(Number)
  7. if math.floor(Number) == Number then
  8. if Number%3 == 0 then
  9. return Number
  10. elseif (Number - 1)%3 == 0 then
  11. return Number - 1
  12. elseif (Number + 1)%3 == 0 then
  13. return Number + 1
  14. end
  15. end
  16. return Number
  17. end
  18.  
  19. local LastPosition = CFrame.new()
  20. while true do
  21. if Mouse.Target then
  22. if Mouse.Target.Name == "Base" then
  23. local TycoonBase = Mouse.Target
  24. local TycoonBaseSizeX, TycoonBaseSizeZ
  25. local HitboxSizeX, HitboxSizeZ
  26.  
  27. TycoonBaseSizeX, TycoonBaseSizeZ = TycoonBase.Size.x, TycoonBase.Size.z
  28. HitboxSizeX, HitboxSizeZ = Hitbox.Size.x, Hitbox.Size.z
  29.  
  30. local TycoonTopLeft = TycoonBase.CFrame * CFrame.new(Vector3.new(TycoonBase.Size.x/2, 0, TycoonBase.Size.z/2))
  31. local BaseAngleX, BaseAngleY, BaseAngleZ = CFrame.new(TycoonBase.Position, (TycoonBase.CFrame*Vector3.new(1, 0, 0))):toEulerAnglesXYZ()
  32. local VectorRotation = CFrame.Angles(BaseAngleX, BaseAngleY, BaseAngleZ)
  33.  
  34. local RoundByThreeX = RoundByThree(math.floor(Mouse.Hit.p.x - TycoonTopLeft.x))
  35. local RoundByThreeZ = RoundByThree(math.floor(Mouse.Hit.p.z - TycoonTopLeft.z))
  36.  
  37. if RoundByThreeX < -TycoonBaseSizeX + HitboxSizeX then
  38. RoundByThreeX = RoundByThreeX + HitboxSizeX
  39. end
  40. if RoundByThreeZ < -TycoonBaseSizeZ + HitboxSizeZ then
  41. RoundByThreeZ = RoundByThreeZ + HitboxSizeZ
  42. end
  43. local VectorComponent1 = CFrame.new(Vector3.new(TycoonTopLeft.x, Mouse.Target.Position.y, TycoonTopLeft.z))
  44. local VectorComponent2 = CFrame.new(Vector3.new(RoundByThreeX, Mouse.Target.Size.y/2, RoundByThreeZ))*VectorRotation
  45. local VectorComponent3 = CFrame.new(Vector3.new(-HitboxSizeX/2, Hitbox.Size.y/2, -HitboxSizeZ/2))
  46. local NewVector = VectorComponent1*VectorComponent2*VectorComponent3
  47. local RegionVectorMin = NewVector * CFrame.new(Vector3.new(HitboxSizeX/2, -Hitbox.Size.y/2, HitboxSizeZ/2))
  48. local RegionVectorMax = NewVector * CFrame.new(-Vector3.new(HitboxSizeX/2, -Hitbox.Size.y/2, HitboxSizeZ/2))
  49. local Hitboxes = game.Workspace:FindPartsInRegion3(
  50. Region3.new(
  51. Vector3.new(
  52. math.min(RegionVectorMin.x, RegionVectorMax.x),
  53. math.min(RegionVectorMin.y, RegionVectorMax.y),
  54. math.min(RegionVectorMin.z, RegionVectorMax.z)
  55. ) + Vector3.new(0.1, 0, 0.1),
  56. Vector3.new(
  57. math.max(RegionVectorMin.x, RegionVectorMax.x),
  58. math.max(RegionVectorMin.y, RegionVectorMax.y),
  59. math.max(RegionVectorMin.z, RegionVectorMax.z)
  60. ) - Vector3.new(0.1, 0, 0.1)
  61. ), nil, 100
  62. )
  63.  
  64. local ModelColliding = false
  65. for i, Hitbox in pairs(Hitboxes) do
  66. if Hitbox.Name == "Hitbox" and not Hitbox:IsDescendantOf(Visual) then
  67. ModelColliding = true
  68. end
  69. end
  70.  
  71. if not ModelColliding then
  72. LastPosition = NewVector
  73. end
  74. Visual:SetPrimaryPartCFrame(LastPosition)
  75. end
  76. end
  77. wait()
  78. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement