I’m currently trying to build a beeswarm mechanic in my game. When the player fails to shake the hive, the bees should chase and sting the player. Therefore the bees need to be quicker than the player. I have two problems:
- As you can see in the clip, the bees move at the same speed as the player. The player can keep running away, and they’ll never sting the player. This doesn’t change no matter the value of the variable named ‘‘speed’’.
In other words, I want the bees to be able to move at a constant speed, determined by a variable.
- The movement of the bees is really jittery, and I don’t know how to fix it.
This is the clip(sorry for the potato quality, the file was too large):
This is the code I used:
followConnection = RunService.Heartbeat:Connect(function(dt)
if bee and target and bee.PrimaryPart then
local targetPosition = target.Position + Vector3.new(offsetX, 0, offsetZ)
local direction = (targetPosition - beePrimary.Position).Unit
local distance = (targetPosition - beePrimary.Position).Magnitude
-- Move towards the target
local moveStep = speed * dt
if distance > 1 then
-- Compute a point 2 studs beyond the target position
local beyondTarget = targetPosition + direction * 2
-- Move and look at the "beyond" point
beePrimary.CFrame = CFrame.new(beePrimary.Position + direction * moveStep, beyondTarget)
end
end
end)
I’m grateful for any answers, I’ve been breaking my head over this :\