I have created a rotating part using cylindrical constraint, it is an obstacle for an obby. It is meant to push the player, but when it touches the player, it just stops. I have tried messing with its physical properties, given it huge mass, elasticity, still the issue persists.
Is there a script with which I can rotate the part, so that it pushes the player?
It operates on physics, so to slow it a bit increase the density of the object and lower the velocity down a bit until u get your desired speed and weight.
Make the part rotate with a script and forget the cylindrical constraint, they are a little bit archaic and most of the physics can be simulated. This will also allow you to apply any force to the player when touch happens. Random mega forces sometimes, like blasting the player away, or just normal push forces. Either way locally calculated physics can do this, and gives you absolute control over the outcome.
You can rotate it with this. With no need for forces, mass, density, unpredictable physics or anything.
local Cylinder = script.Parent; -- or path.to.your.cylinder
local cFrame = CFrame.new(); -- a blank cframe to rotate over, we don't rotate the original frame we accumulate changes here because things can drift and move over a long time
local Origin = Cylinder :GetPivot().Position; -- the cylinders original position from the model/parts pivot point (the thing you rotate/move it over in Studio with the arrows around it)
local rotationSpeed = 5; -- this is the speed you want the cylinder to rotate at
local rotationAxis = Vector3.yAxis; -- the axis of rotation of the Cylinder (I arbitrarily chose the y-axis)
-- this is a stepper function that runs very fast and allows you to animate on a consistent frame rate
-- (i.e. the same for all players) deltaTime ensures the motion is the same on all devices and for all
-- players so you get no inconsistencies between clients because skips/drops in rate are accounted for
game:GetService("RunService").Heartbeat:Connect(function(deltaTime)
-- apply our rotation to the empty cFrame and not the actual CFrame of the cylinder
-- this is adjusted for frame rate (deltaTime)
cFrame *= CFrame.fromAxisAngle(rotationAxis,rotationSpeed *deltaTime);
-- this is the part where we actually move the cylinder cFrame = our new rotation
-- to this we add the original position (Origin) so it doesn't move from where it is sat
Cylinder:PivotTo(cFrame + Origin);
end)
I have chosen Vector3.yAxis as the rotation since I didn’t know the axis of rotation of your cylinder, (these are predefined in Roblox) if you want X rotation change rotationAxis to Vector3.xAxis or if you want Z rotation change rotationAxis to Vector3.zAxis.