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()
Oh this looks interesting. Im gonna try to replicate it later.
Sorry if I’m completely misunderstanding your post, but can’t you just make tweenTime lower?
yes this does work only problem is that it doesn’t turn and I have already a system like that. Thank you anyways.
Sorry but you must be doing something wrong because when I test the script the part does turn correctly for me
Basically how the tween works is that it moves the zombie whilst turning the zombie for a short amount of time, then it goes back to usual moving. So if i lower tweenTime, the zombie’s speed will be very high for like 0.5 seconds then it will go back to normal. My main issue though is that the zombie’s orientation is like not turning at the right speed.
oh? does it have to be anchored or unanchored?
the cframe is 10% through the path and the zombie only turns like if the destination was all the way at the end of the path.
I’m testing with the part anchored
are you keeping a visual indicator of where the part is facing? Because I placed a decal and the part isn’t rotating at all.
Yes I did and for me it’s rotating, I’ll try to upload a video if it lets me
don’t need that, I found the problem, I forgot to update the topic. But thanks anyways!
anytime!
also, out of curiosity, what did you end up doing to solve your issue?
well, I had simply misunderstood my own code (LOL).
I just ended up offsetting the Orientation of the cframe variable, and it worked out.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.