How do I make a platform dip when player is on it
I have a character here
I want to make the platform be rotated like this because the player is weighing it down
and when it is on the other side I want it to be rotated like this
How can I achieve this effect?
1 Like
A. Use Hinge Constraints near the middle of the platform.
B. Code something else if you want a bit more control, made this for you but it’s probably not the best, so tweak it if you’d want to use this.
[edit: please anchor the part
]
local platform = script.Parent
--settings
local tiltSpeed = 1
local maxAngle = 15
local resetWhenEmpty = false
local rs = game:GetService("RunService")
local plrs = game:GetService("Players")
rs.Heartbeat:Connect(function(dt)
local tilt = Vector3.new(0,0,0)
local count = 0
for _,p in pairs(plrs:GetPlayers()) do
local c = p.Character
local root = c and c:FindFirstChild("HumanoidRootPart")
if root then
local rayOrigin = root.Position
local rayDir = Vector3.new(0,-5,0)
local params = RaycastParams.new()
params.FilterDescendantsInstances = {c}
params.FilterType = Enum.RaycastFilterType.Exclude
local result = workspace:Raycast(rayOrigin,rayDir,params)
if result and result.Instance == platform then
count = count + 1
local pos = platform.CFrame:PointToObjectSpace(root.Position)
local x = math.clamp(pos.X/(platform.Size.X/2),-1,1) * maxAngle
local z = math.clamp(pos.Z/(platform.Size.Z/2),-1,1) * maxAngle
tilt += Vector3.new(x,0,z)
end
end
end
local goal
if count > 0 then
tilt /= count
goal = CFrame.Angles(math.rad(tilt.Z),0,math.rad(-tilt.X))
elseif resetWhenEmpty then
goal = CFrame.new()
else
return
end
local cfNow = CFrame.new(platform.Position) * platform.CFrame.Rotation
local cfGoal = CFrame.new(platform.Position) * goal
platform.CFrame = cfNow:Lerp(cfGoal,math.clamp(tiltSpeed*dt*60,0,1))
end)
--btw pls put this in the part .p.
It worked but you have to set network owner to a player for it to work