I want to make a character move along a road for a TD game and I am using GnomeCode’s script for this. The issue is that before reaching every checkpoint my character drifts to the side significantly before correcting it’s course about half way through. This technically works but looks ugly and I would much rather it actually gets to the intended destination directly. In an attempt to remedy the problem I have about 20 nodes on a short path but the problem persists.
Code:
local character = script.Parent
local waypoints = workspace.Nodes
for waypoint=1, #waypoints:GetChildren() do
character.Humanoid:MoveTo(waypoints[waypoint].Position)
character.Humanoid.MoveToFinished:Wait()
end
You can try to use tween instead. Personally I like it better since MoveTo is… sub-par.
local ts = game:GetService("TweenService")
local character = script.Parent
local waypoints = workspace.Nodes
for waypoint=1, #waypoints:GetChildren() do
local twn = ts:Create(character.HumanoidRootPart,TweenInfo.new(1,Enum.EasingStyle.Cubic, Enum.EasingDirection.Out),{CFrame = CFrame.new(waypoints[waypoint+1],waypoints[waypoint+2])})
twn:Play()
twn.Completed:Wait()
end
You need to do the position of the waypoint rather than just the waypoint. It is attempting to create a CFrame out of instances, where you need to create it from the position of the instance.
I am now incredibly confused. I am using the code:
local ts = game:GetService("TweenService")
local character = script.Parent
local waypoints = workspace.Nodes
for waypoint=1, #waypoints:GetChildren() do
local twn = ts:Create(character.HumanoidRootPart,TweenInfo.new(1,Enum.EasingStyle.Cubic, Enum.EasingDirection.Out),{CFrame = CFrame.new(waypoints[waypoint+1].Position,waypoints[waypoint+2].Position)})
twn:Play()
twn.Completed:Wait()
end
Whenever I run this code the character zooms BACKWARDS at an incredible speed. I have made sure the root part is facing forwards. I was going to attach a video but xbox game bar decided to just not launch so I cannot but it takes about 4 seconds for the character to get out of eyesight, which I assume is the edge of the baseplate
And here is the log (I doubt it will matter but might as well include it)
16:53:05.553 7 is not a valid member of Folder “Workspace.Nodes” - Server - Movement:6
16:53:05.553 Stack Begin - Studio
16:53:05.553 Script ‘Workspace.Growth.Movement’, Line 6 - Studio - Movement:6
16:53:05.553 Stack End - Studio
Update: The character no long launches backward at the speed of light. It now moves between the checkpoints but there is a series of other problems. It turns to face the next node as it is moving. Example: it is moving between nodes 3 and 4. While it moves it is constantly rotating until it is in a position that faces node 5 as it reaches node 4, and so on. The other problem is that it moves between the nodes in 5 seconds (changed from the 1 I had previously) no matter than distance, and it eases between the 2. I need to fix all these problems but I am unfamiliar with TweenService and honestly have no idea where to begin.
Edit: I also want the character to move fairly slow, about 6-8 walkspeed if it was using moveTo
Code:
local ts = game:GetService("TweenService")
local character = script.Parent
local waypoints = workspace.Nodes
for waypoint=1, #waypoints:GetChildren() do
local twn = ts:Create(character.HumanoidRootPart,TweenInfo.new(5,Enum.EasingStyle.Cubic, Enum.EasingDirection.Out),{CFrame = CFrame.new(waypoints[waypoint+1].Position,waypoints[waypoint+2].Position)})
twn:Play()
twn.Completed:Wait()
end
I also forgot to mention that when it reaches node 5 (out of 6) it just stops moving and says in output:
17:51:17.984 7 is not a valid member of Folder “Workspace.Nodes” - Server - Movement:6
17:51:17.985 Stack Begin - Studio
17:51:17.985 Script ‘Workspace.Growth.Movement’, Line 6 - Studio - Movement:6
17:51:17.985 Stack End - Studio
Note: The previous problem was with my model’s hitbox glitching as far as I can tell