#How do you limit CFrame.Rotation

1 messages · Page 1 of 1 (latest)

hoary flax
#

I'm trying to make a script that makes a player's hrp's up-down rotation move accordingly with the camera (shiftlock is mandatory already) and this is what I've come up with, but i want to make the up-down rotation be limited to a certain rotation, let's say 30 degrees

local plr = game.Players.LocalPlayer
local cam = workspace.CurrentCamera
game.RunService.Heartbeat:Connect(function()
    plr.Character.HumanoidRootPart.CFrame = cam.CFrame.Rotation + plr.Character.HumanoidRootPart.Position
end)
warm dawn
# hoary flax I'm trying to make a script that makes a player's hrp's up-down rotation move ac...
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")

local plr = Players.LocalPlayer
local cam = workspace.CurrentCamera

local MAX_PITCH = math.rad(30)

RunService.Heartbeat:Connect(function()
    local char = plr.Character
    if not char then return end

    local hrp = char:FindFirstChild("HumanoidRootPart")
    if not hrp then return end

    local pitch, yaw, _ = cam.CFrame:ToOrientation()

    pitch = math.clamp(pitch, -MAX_PITCH, MAX_PITCH)

    hrp.CFrame =
        CFrame.new(hrp.Position) *
        CFrame.Angles(pitch, yaw, 0)
end)
#

this should work ig

hoary flax
#

ok ty

warm dawn
hoary flax
#

I have run into a new problem where for some reason the player somewhat tilts side to side

#

I feel like my original script already had this issue and I couldn't notice because of the bigger issue

warm dawn
hoary flax
#

it tils forward and back, it just also has that problem of tilting form side to side

#

okay so

#

there seems to be a bug where the forward backward tilt also breaks?

#

@warm dawn could you help me so that the tilting only happens visually because currently the tilting somewhat messes up the physics

young oar
young oar
warm dawn
#

I'm tired, so sorry for the mistake

hoary flax
#

I don't play around with CFrames much so honestly I feel like I can't say much about it 😭

sonic nimbus
#
local Players = game:GetService("Players");

local RunService = game:GetService("RunService");

local LocalPlayer = Players.LocalPlayer;

local CurrentCamera = workspace.CurrentCamera;

local MAX_PITCH = math.rad(7);

local baseC0 = nil;

RunService.RenderStepped:Connect(function()
    local character = LocalPlayer.Character;
    if not character then return; end;
    if not character:FindFirstChild("HumanoidRootPart") then return; end;
    if not character.HumanoidRootPart:FindFirstChild("RootJoint") then return; end;

    local HumanoidRootPart = character.HumanoidRootPart;
    
    local RootJoint = HumanoidRootPart.RootJoint;

    if not baseC0 then
        baseC0 = RootJoint.C0;
    end

    local pitch = select(1, CurrentCamera.CFrame:ToOrientation());
    
    pitch = math.clamp(-pitch,-MAX_PITCH,MAX_PITCH);

    RootJoint.C0 = RootJoint.C0:Lerp(baseC0 * CFrame.Angles(pitch, 0, 0), 0.25);
end)```
#

this should only tilt the character both forwards and backwards only.

hoary flax
#

how does the rootjoint work

#

wait no nvm

#

its 4 am for me

#

my brain is not braining

sonic nimbus
hoary flax
#

its a motor6d what am i talking abt 😭

#

yeah exactly

sonic nimbus
hoary flax
# sonic nimbus

the thing with rotating the torso is that I want it not to mess with the physics

#

i just want it to be visual

#

how would i like

#

do that i suppose

sonic nimbus
hoary flax
#

oh wow it works

#

but wait im confused

#

i tried altering the torso earlier and it messed with the humanoidstate which messed with the idle/freefalling animations

sonic nimbus
# hoary flax why doesnt this do that

The torso connects to all of the rigs body parts such as the arms and legs. The root joint connects to the torso to the humanoidrootpart. moving/rotating the torso collides with the rootpart having buggy physics

hoary flax
#

ohhhhh

sonic nimbus
#

so rotating the rootjoint just rotates the torso and since the body parts are connected to the torso they follow with it.

hoary flax
#

so you can't manipulate the torso's rotation directly and have to manipulate the motor6d so it doesnt collide with the hrp

#

i think i get it now

#

thx

sonic nimbus
#

changing the values on the rootJoint just changes how the body is attached to the humanoidrootpart

hoary flax
#

got it