[SOLVED] Tweens Doesn't work as Intended

im gonna try adding “Orientation” to the property table. But im pretty sure Orientation is read only.

This should allow you to do what you want:

local tweenInfo = TweenInfo.new(
	2, -- Change the speed to what you want
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.In,
	0,
	false,
	0)

local tweenInfo2 = TweenInfo.new(
	1, -- Change the speed to how fast you want the part to turn
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.In,
	0,
	false,
	0)

local tweenService = game:GetService"TweenService"

local zombie = workspace.Part

local tweens = {}

local waypoints = workspace.Waypoints

for i in waypoints:GetChildren() do
	tweens[i] = {
		tweenService:Create(zombie, tweenInfo, {Position = waypoints[i].Position}),
		tweenService:Create(zombie, tweenInfo2, {CFrame = waypoints[i].CFrame})}
end

for _, tween in tweens do
	tween[1]:Play()
	tween[1].Completed:Wait()
	tween[2]:Play()
	tween[2].Completed:Wait()
end

this maybe would work, but I am pretty sure this would make the enemy stop to turn, which is my problem here.

ive tried running 2 tweens at once, but only 1 runs.

First you said:

Now you say:

At this point I’m convinced that there’s a chance what you want is either impossible or you’re doing a pretty bad job explaining what you want the end result to be like. I recommend you test the script I gave you and see whether it achieves something at least close to what you desire

A cframe is the position and orientation, so it should only tween it, if you want to do it individually, your best bet is tweening/lerping the position and orientation individually. You can get required orientation with some cframe math such as node.CFrame:Inverse() * Mob.Cframe this will give a difference in orientation… So that difference_cf:ToOrientation() giving you the x,y,z in radians and you should be able to find out the rest.

1 Like

oop, on that second quote, i typo’d. I meant move.

Well the part will need to move at least a bit to turn and face the correct direction

Ok, I will re-explain what I need.
First off, if you don’t understand what im trying to replicate, since english is not my native language, check out this game’s zombies:

If you don’t want to check this game for a minute, just read carefully what Im about to say.

So, imagine that the enemy spawns at the entrance. After it spawns, it goes directly to the first waypoint, using TweenService. After the tween has finished, the enemy faces the next waypoint on the list, which in this case is waypoint 2. But, the enemy needs to face smoothly the next waypoint. So, in this case, he turns but he NEVER stops walking. Even for turning to the next waypoint. While he turns, he still continues walking. But, in my present script, when the enemy reaches its defined waypoint, it stops to face the next waypoint. He will not continues walking, which is my problem. He will only continue walking if the turn tween has been completed. This is really not what I want, I never want him to stop!

Thats what my problem is.
If my explainations don’t make sense, then go play the game I linked to you.
and you can see my full script a bit higher up in the conversation.

I played the game, you won’t be able to do that using TweenService. I’ll write a script that does this but it will take a bit of time

dont write me a full script, tell me what I need to use and the basics of it.

This is exactly what you need to achieve what you want:

local speed = 1 -- The smaller the value the slower the speed

local zombie = workspace.Part

local waypoints = workspace.Waypoints

local start = zombie.CFrame
local goal

for i in waypoints:GetChildren() do
	if goal then
		start = goal
		goal = waypoints[i].CFrame
	else
		goal = waypoints[i].CFrame
	end

	local x = 0

	repeat
		x = math.min(task.wait() * speed + x, 1)

		zombie.CFrame = start:Lerp(goal, x)
	until x == 1
end

could you explain to me what this does?

It gradually increases x using the deltatime returned by task.wait multiplied by the speed whilst making sure that it never goes past the value of 1 else you’ll get a weird result if it does

Oh ok, im gonna try your thing and hopefully this works.

btw if it still doesn’t work then try this:

local speed = 1/4 -- The smaller the value the slower the speed

local zombie = workspace.Part

local waypoints = workspace.Waypoints

local start = zombie.Position
local goal

for i in waypoints:GetChildren() do
	if goal then
		start = goal
		goal = waypoints[i].Position
	else
		goal = waypoints[i].Position
	end

	local x = 0

	repeat
		x = math.min(task.wait() * speed + x, 1)

		zombie.Position = start:Lerp(goal, x)
	until x == 1

	zombie.CFrame = waypoints[i].CFrame
end

Okay I was on mobile when typing this. So if I’m not mistaken, this is basically what you’re aiming for.

I got on studio just to make sure I got it working before I send anything meaningful.

-- Finding the CFrame you want the troop or mob to look
-- Getting the difference between the troop/mob's current CFrame and wanted result
-- Such that:
Mob.CFrame:Inverse() * LookCFrame
-- We can use this to get the difference in orientation from CF A and CF B

-- Using the difference in CFrames, you can convert this into an differenc
-- In orientation: like so
local difference = Mob.CFrame:Inverse() * LookCFrame
local x, y, z = difference:ToOrientation() -- In rads
local orientation_difference = Vector3.new(math.deg(x), math.deg(y), math.deg(z))

-- then with this we can get the new orientation that the troop should have
local new_orientation = Mob.Orientation + orientation_difference
-- This works in 3 dimensions, you can technically just face your nodes
-- towards the next goal and have your mob replicate that orientation as well
-- then you can easily add how fast you want it to turn

This is what I personally used with superb variable naming:

local f = workspace.OrientationTest; 
local a = f.A; 
local b = f.B; 
local diff = a.CFrame:Inverse() * CFrame.lookAt(a.Position, b.Position); 
local x, y, z = diff:ToOrientation(); 
local orientation = Vector3.new(math.deg(x), math.deg(y), math.deg(z));

local speed = 18
local rot_speed = 90
local distance = (a.Position - b.Position).Magnitude

local ts = game:GetService("TweenService")
local t1 = ts:Create(a, TweenInfo.new(distance/speed, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut), {Position = b.Position})
local t2 = ts:Create(a, TweenInfo.new(orientation.Y / rot_speed, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {Orientation = a.Orientation + orientation})

t1:Play(); t2:Play()
1 Like

Oh this looks interesting. Im gonna try to replicate it later.

1 Like

Sorry if I’m completely misunderstanding your post, but can’t you just make tweenTime lower?

1 Like

yes this does work only problem is that it doesn’t turn and I have already a system like that. Thank you anyways.

1 Like