Part facing forward direction during tween

Hi and sorry for the confusing title.

I’m using TweenService to move a part down a path created by PathfindingService. Everything works correctly except one problem: The part does not face the correct direction. PathfindingService doesn’t provide any kind of direction. What should I do in order to get it to face the direction it’s going?

In the gif above, the part doesn’t face the forward direction, rather the direction in which it was instantiated in.

local path = pfs:CreatePath()
path:ComputeAsync(initialStartingPosition,start)
for i,v in pairs(path:GetWaypoints()) do
	local twn = TweenService:Create(g,TweenInfo.new(0.5,Enum.EasingStyle.Linear),{Position=v.Position})
	twn:Play()
	twn.Completed:Wait()
end

Note: I’m not looking for the part to face the player. I’m looking for it to face the direction it’s moving.

Thanks.

3 Likes

You are tweening only the parts position, if you want its rotation to tween as well you should use its CFrame as the tween property.

EDIT: This wont make the part face the direction its moving though, but it will rotate it to match the target property

4 Likes

I’m aware of that. The problem (as stated above) is that PathfindingService doesn’t provide a directional vector I can use to face the part toward the moving direction, which is why I’m asking how I should make the part face the direction it’s moving.

1 Like

Oh, I see. Subtract the start position from the end position to get the directional vector.

2 Likes

I’ll try this when I can, thanks.

1 Like

Won’t this only make it face one direction the entire tween?

@Thundermaker300 I don’t know how your code is set out, but I’m going to assume you have waypoints set in a table. If not, my bad.

When Tweenies between the waypoints, you can use the next waypoint in the table as the directional vector for each ‘segment’ of the tween.

3 Likes

Worked, however occasionally the part will look directly down. Wonder why that could be?
Code:

for i,v in pairs(path:GetWaypoints()) do
		local nex = path:GetWaypoints()[i+1]
		if nex then nex = nex.Position+Vector3.new(0,2,0) else nex = v.Position + Vector3.new(1,2,0) end
		local twn = game:GetService("TweenService"):Create(g,TweenInfo.new(0.5,Enum.EasingStyle.Linear),{CFrame=CFrame.new(v.Position+Vector3.new(0,2,0),nex)})
		twn:Play()
		twn.Completed:Wait()
	end
1 Like

How often? Is it random or is there a pattern to it?

1 Like

It appears to happen randomly, I can’t find any recognizable pattern after executing it 15 times (in groups of 5).

1 Like

I have no idea. Could you attatch a video that shows this?

1 Like


This is the first time I was able to reproduce it with every object, previously only one would go down and up while the rest would go straight normally.

Edit: Only one did it previously, but since I moved the starting point all five started to do it.

1 Like

It’s possible that this is an issue with the actual path. You could visualise it and see if any of the points look strange.

1 Like

I figured it was a problem with the path, the confusing part was that prior to moving the starting position only one did it, now all five do it.

3 Likes