Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make humanoid float with moving part?

Asked by 5 years ago

hi there, I need to find out how to make humanoid also float with moving part. as of right now the humanoid seems to be drowned in the moving part when this part moves up and down using below code.

01local player = game.Players.LocalPlayer
02local part = workspace.Part
03 
04part.Touched:Connect(function()
05    player.Character:SetPrimaryPartCFrame(player.Character.HumanoidRootPart.CFrame + (part.CFrame.LookVector * Vector3.new(0.05, 0, 0)))
06end)
07 
08local brick=script.Parent
09while wait(1) do
10for I=1,5 do
11brick.CFrame=brick.CFrame+Vector3.new(0,5,0)
12wait(2)
13end
14wait(1)
15for I=1,5 do
16brick.CFrame=brick.CFrame+Vector3.new(0,-0.2,0)
17wait()
18end
19end

any idea of how to make humanoid can stand on the moving part when it moved up?

1 answer

Log in to vote
0
Answered by 5 years ago

Moving parts that interact with the player is complicated. Right now your animation for the brick looks fine, but when a player is standing on it, it teleports right through. This is because, according to the physics engine, the brick still isn't moving. To actually move it you use a BodyPosition.

A BodyPosition and similar objects tell the physics engine what to do. In this case, it makes the brick glide to a position in space, which is what you want. It can be applied like this:

01local brick = script.Parent
02 
03local bodyPosition = Instance.new("BodyPosition",brick)
04 
05while true do
06    bodyPosition.Position = brick.Position+Vector3.new(0,25,0) --This position should be the FINAL destination of the UP movement
07    wait(2) --Wait for the up movement to finish
08    bodyPosition.Position = brick.Position+Vector3.new(0,-25,0) --This position should be the FINAL destination of the DOWN movement
09    wait(2) --Wait for the down movement to finish
10end

Make sure that the brick is NOT anchored. Also, If the part isn't moving, the MaxForce of the bodyPosition might be too low. You can replace it by going

1bodyPosition.MaxForce = Vector3.new(10000,10000,10000) --10000 is just an example number, you can tinker with it

If the brick goes to far and rubberbands back, the D ("dampening") is too low. Set it higher by going

1bodyPosition.D = 3000 --3000 is just an example number

Feel free to tinker with these numbers to get the effect you want. For further reading you can use this on the wiki

0
I already put that script for the brick and somehow the brick isn't moving. did I miss anything? jacobian65 19 — 5y
Ad

Answer this question