Hi,
-
What do you want to achieve?
I want my robot to look at the waypoint of the pathfindingservice he is moving to. -
What is the issue?
When I make my robot look at the waypoint, it is spinning around randomly. -
Extra information:
The robot is a model and doesn’t have any humanoids or so.
This is my code for moving the robot with pathfindingservice:
local Pathfindingservice = game:GetService("PathfindingService")
local path = Pathfindingservice:CreatePath()
path:ComputeAsync(Robot.PrimaryPart.Position, RandomPlace.Position) -- The path between the robot and a randomly chosen place
local waypoints = path:GetWaypoints()
local timeperwaypoint = (30/PlayerStats.RobotSpeed.Value)/#waypoints -- The time between each waypoint
for i, waypoint in pairs(waypoints) do
wait(timeperwaypoint)
local part = Instance.new("Part")
part.Size = Vector3.new(0.6,0.6,0.6)
part.Position = waypoint.Position + Vector3.new(0,2,0)
part.Anchored = true
part.CanCollide = false
part.Parent = game.Workspace
Robot:SetPrimaryPartCFrame(CFrame.lookAt(Robot.PrimaryPart.Position, part.Position)) -- Make the robot look at the waypoint (here is the problem I think)
local TweenService = game:GetService("TweenService")
local RobotTweenInfo = TweenInfo.new(
timeperwaypoint,
Enum.EasingStyle.Linear,
Enum.EasingDirection.InOut
)
local tweenRobot = TweenService:Create(Robot.PrimaryPart, RobotTweenInfo, {CFrame = part.CFrame}) -- Tween the robot to the waypoint
tweenRobot:Play()
part:Destroy()
end
Here you can see what is happening:
Hope you guys can help me!
Thanks!