Bee Movement like Bee Swarm Simulator

Hey!
I’m trying to replicate how Bee Swarm Simulator made the bees movement, so far it works fine when you’re idle, but I don’t like the way it looks when you move.

I’m using client-side rendering to reduce server-side lag and do smooth tweens on the client, the server just tells the cframe where the “bee” would move and the client detect the change and move the “bee” to the position.

What I want to achieve: (this is not bee swarm simulator, but a fan-made of it)

My version:

Scripts:

Server:

function Bee:Init()
	task.spawn(function()
		while self.Object.Parent do
			local character = self.Player.Character or self.Player.CharacterAdded:Wait()
			local humanoid = character.Humanoid
			
			local oldCFrame = self.LastCFrame
			local newCFrame = self:GetCFrame()

			local distance = (newCFrame.Position - oldCFrame.Position).Magnitude
			local t = (distance/self.Speed) + .5
			
			if humanoid.MoveDirection.Magnitude > 0 then
				self.Object:SetAttribute("CFrame", newCFrame)
				task.wait(t)
			else
				self.Object:SetAttribute("CFrame", newCFrame)
				task.wait(t + rng:NextNumber(3,6))
			end
		end
	end)
end

function Bee:CreateObject()
	local object = Instance.new("Configuration")
	object.Name = self.ID
	
	object:SetAttribute("Name", self.Name)
	object:SetAttribute("CFrame", CFrame.new(0, 0, 0))
	object:SetAttribute("Speed", self.Speed)
	
	object.Parent = bees[self.Player.Name]
	
	return object
end

function Bee:GetCFrame()
	local character = self.Player.Character or self.Player.CharacterAdded:Wait()
	local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
	
	local X = rng:NextNumber(-15, 15)
	local Y = rng:NextNumber(-1, 1)
	local Z = rng:NextNumber(-15, 15)
	
	self.Offset = CFrame.new(X, Y, Z)
	self.LastCFrame = humanoidRootPart.CFrame * self.Offset
	return self.LastCFrame
end

Client:

function BeeController:CreateBee(playerFolder, beeObject)
	if not clientBees[playerFolder] then clientBees[playerFolder] = {} end
	if not clientBees[playerFolder][beeObject.Name] then
		
		local model = ReplicatedStorage.Bees:FindFirstChild(beeObject:GetAttribute("Name")):Clone()
		model:PivotTo(beeObject:GetAttribute("CFrame"))
		model.Parent = beeObject
		
		beeObject:GetAttributeChangedSignal("CFrame"):Connect(function()
			local distance = (model.PrimaryPart.Position - beeObject:GetAttribute("CFrame").Position).Magnitude
			local direction = (model.PrimaryPart.Position - beeObject:GetAttribute("CFrame").Position).Unit
			
			local lookCF = CFrame.lookAt(model.PrimaryPart.Position, model.PrimaryPart.Position + direction * -1)
			local tween = TweenService:Create(model.PrimaryPart, TweenInfo.new(.25), {CFrame = lookCF})
			tween:Play()
			tween.Completed:Wait()
			
			local tween = TweenService:Create(model.PrimaryPart, TweenInfo.new(distance/beeObject:GetAttribute("Speed"), Enum.EasingStyle.Linear), {CFrame = CFrame.new(beeObject:GetAttribute("CFrame").Position, beeObject:GetAttribute("CFrame").Position+ direction * -1)})
			tween:Play()
			tween.Completed:Wait()
			
			local tween = TweenService:Create(model.PrimaryPart, TweenInfo.new(.25), {CFrame = CFrame.new(model.PrimaryPart.CFrame.Position) * CFrame.Angles(beeObject:GetAttribute("CFrame"):ToEulerAnglesXYZ())})
			tween:Play()
			tween.Completed:Wait()
		end)
		
		clientBees[playerFolder][beeObject.Name] = beeObject
	end
end

Any help is appreciated,

Thanks.

1 Like

For the final position is looks like most of them seem to face the same orientation once they reach their goal. Is that because all the created parts have the same look vector?

The Bee Swarm bees also seem to have a Y-axis bob as they move. Replicating this might make them look more natural overall.

1 Like

I made it so, when they reach the final position, they face where the character is looking at, in case you didn’t notice Bee Swarm does the same.

For the Y axis, I’m already doing it, but the offset is so small that it’s kinda hard to see in the video.

Thanks for your reply!