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.
01 | local player = game.Players.LocalPlayer |
02 | local part = workspace.Part |
03 |
04 | part.Touched:Connect( function () |
05 | player.Character:SetPrimaryPartCFrame(player.Character.HumanoidRootPart.CFrame + (part.CFrame.LookVector * Vector 3. new( 0.05 , 0 , 0 ))) |
06 | end ) |
07 |
08 | local brick = script.Parent |
09 | while wait( 1 ) do |
10 | for I = 1 , 5 do |
11 | brick.CFrame = brick.CFrame+Vector 3. new( 0 , 5 , 0 ) |
12 | wait( 2 ) |
13 | end |
14 | wait( 1 ) |
15 | for I = 1 , 5 do |
16 | brick.CFrame = brick.CFrame+Vector 3. new( 0 ,- 0.2 , 0 ) |
17 | wait() |
18 | end |
19 | end |
any idea of how to make humanoid can stand on the moving part when it moved up?
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:
01 | local brick = script.Parent |
02 |
03 | local bodyPosition = Instance.new( "BodyPosition" ,brick) |
04 |
05 | while true do |
06 | bodyPosition.Position = brick.Position+Vector 3. 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+Vector 3. 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 |
10 | end |
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
1 | bodyPosition.MaxForce = Vector 3. 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
1 | bodyPosition.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