I’m trying to make a slime-like enemy. I would like it to jump up and move forwards at the same time, I’ve drawn out a demonstration here.
I’d like to do this using tweens instead of Humanoid.Jump as it didn’t really produce the results I would like.
I’ve got all the code to get the slime moving on the Z axis, and I have it moving forward by set intervals, but I’m not sure how to modify it’s height in the same way I explained above. This is the code to make it move forwards
local lungeSpeed = .5
local lungeInfo = TweenInfo.new(lungeSpeed,Enum.EasingStyle.Linear)
local lunge = enemyPrimaryPart.CFrame * CFrame.new(0, 0, -movespeed.Value) -- enemyPrimaryPart is the Slimes Primary Part
local lungeTween = TweenService:Create(enemyPrimaryPart, lungeInfo, {CFrame = lunge})
lungeTween:Play()
This seems like a pretty good scenario to use a bezier curve, I would personally use a Quadratic Bezier curve in this scenario.
Here is a somewhat simple implementation of using a Quadratic Bezier curve to move the slime.
local Slime = workspace.Slime.PrimaryPart
local EndPart = workspace.EndPosition
local function quadBezier(t, p0, p1, p2)
return (1-t)^2*p0+2*(1-t)*t*p1+t^2*p2
end
local function jump(partToJump, timeLength, jumpHeight, speed, endPosition)
local startPosition = partToJump.Position
local midpoint = startPosition:Lerp(endPosition, 0.5)
local p1 = midpoint + Vector3.new(0 ,jumpHeight, 0)
for i=0, timeLength, speed do
local pos = quadBezier(i, startPosition, p1, endPosition)
partToJump.CFrame = CFrame.new(pos)
task.wait(0.01)
end
end
while task.wait(3) do
jump(Slime, 1, 5, 0.02, EndPart.Position)
end
Appreciate the reply! This is almost exactly what I’m looking for, I’ve toyed around with it and almost have it fully functional in my script.
Just curious if there was a way to maintain the rotation during the for loop? I’ve tried a few ideas but I cant get it to stay facing the same direction.
Thanks for the help!
EDIT
Actually found the solution here; I just wasn’t using math.rad() when multiplying my angles.