How to prevent a moving part from rotating when colliding

Hello everyone,

I am making a part which is moving horizontally between 2 parts. I want this part to be collidable with players. Everything works fine but when a player touches the moving part, the moving part begins to rotate. Is there a way to prevent the part from rotating when a player collides with it?

These are the 3 parts I am using for this:
image
The parts named “Finish” and “Start” are non-collidable (as you can see in the video). The moving part is collidable.

and this is the script:

start = script.Parent.Parent:FindFirstChild("Start")
finish = script.Parent.Parent:FindFirstChild("Finish")
bodyposition = script.Parent:FindFirstChild("BodyPosition")

while true do
   bodyposition.Position = start.Position
   wait(2)
   bodyposition.Position = finish.Position
   wait(2)
end

Can someone explain me how to prevent the part from rotating when colliding with a player?

2 Likes

I believe the part has CanCollide set to true and isn’t anchored.

This means that if any object (including the player) exerts a force on hit, for example, by walking into it, then the object will be affected and rotate.

To prevent this, you can use the :Lerp() function or use TweenService to make the Part unaffected by other objects. TweenService should also be more efficient than the BodyPosition and also allows you to easily tweak how you want the movement to behave.

2 Likes

The way to do this when using BodyForces is by adding a BodyGyro object inside of the part that you wish to prevent from rotating in certain axes.

https://developer.roblox.com/api-reference/class/BodyGyro

9 Likes

Thanks, this worked.

changed the script to

start = script.Parent.Parent:FindFirstChild("Start")
finish = script.Parent.Parent:FindFirstChild("Finish")
bodyposition = script.Parent:FindFirstChild("BodyPosition")
movingpart = script.Parent

MovingPart.BodyGyro.CFrame = MovingPart.CFrame

while true do
   bodyposition.Position = start.Position
   wait(2)
   bodyposition.Position = finish.Position
   wait(2)
end

I also had to set the BodyGyro MaxTorque to 400000, 400000, 400000

7 Likes