You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
im trying to have the character match the rotation of the part their standing on (in r6)
by using the rootjoint’s c0
-
What is the issue? Include screenshots / videos if possible!
i am not good with cframes/vectors and have no clue how i’d do this
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
ive tried jsut setting the current cframe given frome a devforum script (shown below) as the c0, and c1, but it jsut causes some funky effects to happen
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local char = script.Parent
local rootPart = char:WaitForChild("HumanoidRootPart")
local xzGyro = Instance.new("BodyGyro")
local yGyro = Instance.new("BodyGyro")
yGyro.MaxTorque = Vector3.new(0,3e5,0)
yGyro.P = 5e5
xzGyro.MaxTorque = Vector3.new(3e5,0,3e5)
xzGyro.P = 5e5
xzGyro.Parent = rootPart
local runservice = game:GetService("RunService")
runservice.PreSimulation:Connect(function()
local params = RaycastParams.new()
params.FilterDescendantsInstances = {char}
params.FilterType = Enum.RaycastFilterType.Exclude
local result = workspace:Raycast(rootPart.Position, Vector3.new(0,-10,0), params)
yGyro.CFrame = CFrame.new(rootPart.Position, rootPart.Position + char.Humanoid.MoveDirection*10)
if (result) and result.Normal.Y > 0.85 then
local currentRightVector = rootPart.CFrame.RightVector
local upVector = result.Normal
local newFacialVector = currentRightVector:Cross(upVector)
xzGyro.CFrame = CFrame.fromMatrix(rootPart.Position, currentRightVector, upVector, newFacialVector)
end
end)
(this is my edited version of the script from this post: How to get angle of platform player standing on )
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
this is a local script in startercharacterscripts btw
the issue it that you only used bodygyro objects to rotate the character which doesn’t visually change the char pose we could try something like this
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local player = Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local rootPart = char:WaitForChild("HumanoidRootPart")
local torso = char:WaitForChild("Torso")
local rootJoint = torso:WaitForChild("Root Hip")
local humanoid = char:WaitForChild("Humanoid")
local originalC0 = rootJoint.C0
local xzGyro = Instance.new("BodyGyro")
local yGyro = Instance.new("BodyGyro")
yGyro.MaxTorque = Vector3.new(0, 3e5, 0)
yGyro.P = 5e5
xzGyro.MaxTorque = Vector3.new(3e5, 0, 3e5)
xzGyro.P = 5e5
xzGyro.Parent = rootPart
yGyro.Parent = rootPart
RunService.PreSimulation:Connect(function()
local params = RaycastParams.new()
params.FilterDescendantsInstances = {char}
params.FilterType = Enum.RaycastFilterType.Exclude
local result = workspace:Raycast(rootPart.Position, Vector3.new(0, -10, 0), params)
yGyro.CFrame = CFrame.new(rootPart.Position, rootPart.Position + humanoid.MoveDirection * 10)
if result and result.Normal.Y > 0.85 then
local currentRightVector = rootPart.CFrame.RightVector
local upVector = result.Normal
local newFacialVector = currentRightVector:Cross(upVector)
local rotationCFrame = CFrame.fromMatrix(rootPart.Position, currentRightVector, upVector, newFacialVector)
xzGyro.CFrame = rotationCFrame
rootJoint.C0 = originalC0 * rotationCFrame:ToObjectSpace(CFrame.new(rootPart.Position))
else
rootJoint.C0 = originalC0
end
end)
it does visually change it, it jsut has some issues with pysics and some visual bugs, and the code you put dosent work at all
im jsut trying to get the same affect but using the rootjoint rather then bodygyro
i gotcha could you try this? and lmk
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local rootPart = char:WaitForChild("HumanoidRootPart")
local torso = char:WaitForChild("Torso")
local rootJoint = torso:WaitForChild("Root Hip")
local humanoid = char:WaitForChild("Humanoid")
local originalC0 = rootJoint.C0
RunService.Heartbeat:Connect(function()
local params = RaycastParams.new()
params.FilterDescendantsInstances = {char}
params.FilterType = Enum.RaycastFilterType.Exclude
local result = workspace:Raycast(rootPart.Position, Vector3.new(0, -10, 0), params)
if result and result.Normal.Y > 0.85 then
local currentRightVector = rootPart.CFrame.RightVector
local upVector = result.Normal
local newFacialVector = currentRightVector:Cross(upVector)
local rotationCFrame = CFrame.fromMatrix(Vector3.new(), currentRightVector, upVector, newFacialVector)
rootJoint.C0 = originalC0 * rotationCFrame
else
rootJoint.C0 = originalC0
end
local moveRotation = CFrame.new(Vector3.new(), humanoid.MoveDirection)
rootJoint.C0 = rootJoint.C0 * moveRotation
end)
im assuming this is made for r15, cause uuhhh
(btw i had to change it to the correct rootjoint)
1 Like
no problem i updated the code should works fine for r6 could you try it ?
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local rootPart = char:WaitForChild("HumanoidRootPart")
local torso = char:WaitForChild("Torso")
local rootJoint = torso:WaitForChild("Root Hip")
local humanoid = char:WaitForChild("Humanoid")
local originalC0 = rootJoint.C0
RunService.Heartbeat:Connect(function()
local params = RaycastParams.new()
params.FilterDescendantsInstances = {char}
params.FilterType = Enum.RaycastFilterType.Exclude
local result = workspace:Raycast(rootPart.Position, Vector3.new(0, -10, 0), params)
if result and result.Normal.Y > 0.85 then
local currentRightVector = rootPart.CFrame.RightVector
local upVector = result.Normal
local newFacialVector = currentRightVector:Cross(upVector)
local rotationCFrame = CFrame.fromMatrix(Vector3.new(), currentRightVector, upVector, newFacialVector)
rootJoint.C0 = originalC0 * rotationCFrame
else
rootJoint.C0 = originalC0
end
local lookVector = (rootPart.Position + humanoid.MoveDirection) - rootPart.Position
if lookVector.Magnitude > 0 then
local moveRotation = CFrame.new(Vector3.new(), lookVector)
rootJoint.C0 = rootJoint.C0 * CFrame.new(0, 0, 0) * moveRotation
end
end)
well its a lil different
btw, rootjoint needs to be:
local rootJoint = rootPart:WaitForChild(“RootJoint”)