-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patholdFollow.lua
More file actions
128 lines (91 loc) · 3.84 KB
/
Copy patholdFollow.lua
File metadata and controls
128 lines (91 loc) · 3.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
local RunService = game:GetService("RunService");
local range = 200
local closest
local previousTime = 0
local objectVal = script:WaitForChild("whatever")
local owner = objectVal.Value
local check = 0
local times = 0
local sign = 1
--local tweenValue = Vector3.new(0,0,0)
RunService.Heartbeat:Connect(function()
if tick() - previousTime > .1 then
for _, part in ipairs(game.Workspace.enemies:GetChildren()) do
local distance = (owner.Position - part.Position).Magnitude
if not closest or closest ~= part then
end
if distance < range then
--print(distance .. " " .. range)
range = distance
closest = part
end
end
previousTime = tick()
--local j,k,l = lastVectorCFrame:ToOrientation()
--local x,y,z = desiredCFrame:ToOrientation()
--print(j,k,l)
--print(x,y,z)
--print(lastVectorCFrame:ToOrientation())
--print(math.deg(x))
--print(math.deg(j))
--local testVector = Vector3.new(0,math.sin(),math.cos())
--local testDistance = math.acos(math.clamp(lookVector.Unit:Dot(testVector.Unit), -1, 1))
--print(math.deg(distance))
--print(math.deg(testDistance))
end
if closest then
--local amountToAdd = (owner.Position - closest.Position).Magnitude / (2^times)
local desiredCFrame = CFrame.lookAt(owner.Position,closest.Position)
local lookVector = desiredCFrame.LookVector
local lookVectoratan2 = math.atan2(lookVector.Y,lookVector.X)
--local lookVectorASinDeg = math.deg(math.asin(lookVector.Y))
--local lookVectorACosDeg = math.deg(math.acos(lookVector.Z))
--print(lookVectorASinDeg .. " ".. lookVectorACosDeg)
local savedVectorValue = script.savedVector.Value
local savedVectorValueatan2 = math.atan2(savedVectorValue.Y,savedVectorValue.X)
--local savedlookVectorASinDeg = math.deg(math.asin(savedVectorValue.Y))
--local savedlookVectorACosDeg = math.deg(math.acos(savedVectorValue.Z))
--local savedlookVectorASin = math.asin(savedVectorValue.Y)
--local savedlookVectorACos = math.acos(savedVectorValue.Z)
--print(savedlookVectorASinDeg .. " ".. savedlookVectorACosDeg)
--print(math.deg(math.atan2(lookVector.Y,lookVector.Z)) .. " " .. lookVectorACosDeg .. " " .. lookVectorASinDeg)
local difference = math.acos(math.clamp(lookVector.Unit:Dot(savedVectorValue.Unit), -1, 1))
local newVector = Vector3.new(0,math.sin(savedVectorValueatan2 + (sign * difference/2)),math.cos(savedVectorValueatan2 +(difference/2 * sign)))
--print(math.deg(savedVectorValueatan2) .. 1)
--print(math.deg(savedVectorValueatan2 + (sign * difference/2)) .. 2)
--print(math.deg(lookVectoratan2) .. 3)
--print(difference)
print(newVector)
local newDifference = math.acos(math.clamp(lookVector.Unit:Dot(newVector.Unit),-1,1))
if (difference) > (newDifference) then
savedVectorValue = newVector
else
sign = sign * -1
--print(difference .. " ".. newDifference .. " " .. difference - newDifference)
end
local lastVectorCFrame = CFrame.lookAt(owner.Position,owner.Position + savedVectorValue)
owner.CFrame = lastVectorCFrame
owner.Velocity = owner.CFrame.LookVector * 100
--owner.CFrame = CFrame.lookAt(owner.Position, owner.Position + tweenValue)
--owner.Velocity = owner.CFrame.LookVector * 100
times = times + 1
--print(times)
end
end)
--[[
local TweenService = game:GetService("TweenService")
local vectorOffsetLeft = Vector3.new(0,0,3)
local desiredVectorOffset = Vector3.new(0,3,1)
local tweenValue = workspace.player.playerHitbox.tweenValue
local tweenInfo = TweenInfo.new(.10,Enum.EasingStyle.Linear)
local lastFrameTween = Vector3.new(0,0,0)
local tweenForward = TweenService:Create(tweenValue,tweenInfo, { Value = desiredVectorOffset })
local tweenBack = TweenService:Create(tweenValue,tweenInfo, {Value = vectorOffsetLeft})
function shiftTween()
if shiftPressedBoolean == true then
tweenForward:Play()
else
tweenBack:Play()
end
end
]]--