I am trying to make a part rotating with Cframe, however it doesn’t interact with the Player Physics and I would like to know how I would go about doing that.
This is the script I use to rotate
local runService = game:GetService("RunService")
while true do
local dt = runService.Heartbeat:Wait()
script.Parent.CFrame = script.Parent.CFrame * CFrame.Angles(0, math.rad(45*dt), 0)
end
local RunService = game:GetService("RunService")
local dt = 0
while RunService.Hearbeat:Wait() do
dt += 1
script.Parent.CFrame *= CFrame.Angles(0, math.rad(45*dt), 0)
end
This script is definitely cleaner than mine, but it still doesn’t interact with the PlayerPhysics. What I mean is that when the part rotates, I would like the player to rotate with it.
what do you mean? The player is on top of the part.
In the video you see that the player stays in the same position, he doesn’t move when the part rotates
local RS = game:GetService("RunService")
local player = --get player
local char = player.Character or player.CharacterAdded:Wait()
local hrp = char.HumanoidRootPart
local rotatingpart = --get part
local prevcframe=CFrame.new()
RS.Heartbeat:Connect(function()
hrp.CFrame *= rotatingpart.CFrame*prevcframe:Inverse()
prevcframe = rotatingpart.CFrame
end)
What this does is essentially get the difference between the part’s CFrame and its CFrame the previous heartbeat, and changes the player’s HumanoidRootPart’s CFrame by that amount. (Note: This code doesn’t include a check to ensure that the player is actually on top of the part)
That is a solution, however I was able to find an easier one, basically I put a part under my rotating part and added a assemblyAngularVelocity to it so that it would rotate the part on top as well as the player standing on it.