Slime Enemy Movement

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.

Slime Movement

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()

Any help is greatly appreciated!
Thank you.

1 Like

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

Hope this can help.

4 Likes

Hi,

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.

partToJump.CFrame = CFrame.new(pos) * CFrame.Angles(math.rad(startRotation.X),math.rad(startRotation.Y),math.rad(startRotation.Z))

This code worked.

Apologies for the notification, but thank you for the help!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.