To keep things simple, I basically want to make the plate from Slap Battles where it (sometimes) perfectly orbits around the main islands.
When it does a full lap it re-positions itself so it doesn’t eventually go too far out.
In case you’ve never played Slap Battles, here’s a quick video showcasing how the plate moves:
I’ve created this setup with the map (right now it’s just a baseplate) and the plate that spins around it, problem is I have no idea how to make this work.
So far I’ve only got 4 lines of code:
local part = script.Parent
local linear = part.LinearVelocity
local originalCFrame = script.Parent.CFrame
I don’t know if you can make something like that using LinearVelocity or AngularVelocity, but I can suggest using CFrames, lerp, and some orbit equations.
You can make the plate orbit around a position in space.
We can calculate the orbit position like this:
x = cx + radius * math.cos(angle)
y = cy + radius * math.sin(angle)
z = cz -- (for 2D orbit)
We can use CFrame:Lerp()
(here, .Position points to the CFrame) for smooth orbits.
local RunService = game:GetService("RunService")
local plate = workspace.Part -- The part to orbit
local center = Vector3.new(0, 5, 0) -- the center position where you want the plate to orbit
local radius = 10 -- distance from the center to the plate
local speed = 2 -- radians per second
local angle = 0
local lerpSpeed = 5 -- adjust for smoother/faster transition
RunService.Heartbeat:Connect(function(deltaTime)
angle = angle + speed * deltaTime
local targetX = center.X + radius * math.cos(angle)
local targetY = center.Y
local targetZ = center.Z + radius * math.sin(angle)
local targetPosition = Vector3.new(targetX, targetY, targetZ)
plate.Position = plate.Position:Lerp(targetPosition, lerpSpeed * deltaTime)
end)
this is pretty good, but the reason i was thinking of LinearVelocity was to keep the player on it like the real thing, you essentially can ride it all the way around
1 Like
Just apply an assemblylinearvelocity or something like that to the player when they are on the plate.
After some testing, we can just use the LinearVelocity instance and modify the previous equation a bit to make the Velocity vector tangent to the orbit.
local RunService = game:GetService("RunService")
local plate = workspace.Plate
local center = Vector3.new(0, 5, 0)
local radius = 10
local speed = 2
-- (You already have it, but this is for convinience so you dont have to set everything up)
local attachment = Instance.new("Attachment")
attachment.Parent = plate
local linearVelocity = Instance.new("LinearVelocity")
linearVelocity.Parent = plate
linearVelocity.Attachment0 = attachment
linearVelocity.MaxForce = math.huge -- infinite force for stable movement
linearVelocity.VelocityConstraintMode = Enum.VelocityConstraintMode.Vector
--
local angle = 0
RunService.Heartbeat:Connect(function(deltaTime)
angle = angle + speed * deltaTime
-- compute velocity (tangent to the orbit)
local velocityX = -radius * speed * math.sin(angle) -- Derivative of cos(angle)
local velocityZ = radius * speed * math.cos(angle) -- Derivative of sin(angle)
local velocityVector = Vector3.new(velocityX, 0, velocityZ) -- No vertical movement
linearVelocity.VectorVelocity = velocityVector
end)