# How can I "Clamp" this Properly?

``````local bodySom = Instance.new("BodyGyro", script.Parent)
bodySom.Name = "wheelie"

while true do wait()
local value = 45 * script.Parent.CFrame.LookVector.magnitude
end
``````
• The Value of the Orientation(x) doesnt get really clamp Correctly.

• What I want to achieve is that, I want to keep the part from updating from where it is facing and then rotate at a 45Â° angle, I tried using loop thinking that it is the solution but it just created another problem:

What I Expect To Happen:

What Actually Happens:

Sorry my english is kinda bad.

1 Like

So do you want it to stay exactly 45Â° based on what part itâ€™s â€śrestingâ€ť at?

1 Like

Yes, and when I rotate the part it will open/rotate on a 45 angle where it is facing

Not really sure this is what youâ€™re after â€¦ best guess.

``````local bodySom = Instance.new("BodyGyro", script.Parent)
bodySom.Name = "wheelie"

while true do
local value = math.clamp(45 * script.Parent.CFrame.LookVector.magnitude, -45, 45)
local currentRotation = script.Parent.CFrame:pointToWorldSpace(Vector3.new(0, 0, 1))
local targetRotation = script.Parent.CFrame:pointToWorldSpace(Vector3.new(1, 0, 0))
bodySom.CFrame = CFrame.new(script.Parent.Position, script.Parent.Position +
end
``````

Im trying to make a bike wheelie so the while loop is basically to update the BodyGyroâ€™s CFrame to where part/player is facing by using the lookVector.

This is basically what happens(because if you look at the Properties of the BodyGyro > Orientation the value of the x,y,z just keeps adding up, so I tried using â€śmath.clamp()â€ť but it didnt really work):

when you print

value

what is it printing

1 Like

EDIT: This should theoretically work? Not too sure though.

``````local part = script.Parent
local bodyGyro = part.BodyGyro

while true do
local ray = workspace:Raycast(part.Position, part.CFrame.UpVector * -20)
if ray and ray.Instance then
bodyGyro.CFrame *= (CFrame.new(ray.Position).Rotation * CFrame.Angles(math.rad(45), 0, 0))
end
end
``````
1 Like

it just print

45
in the output

have you tried stopping the loop for the wheel

1 Like

Is there a way to like make it rotate like where it is facing like this:

What it does:

Im using the loop so that it always update the CFrame. Im trying to make it work in all directions where the part is facing, without the loop it doesnt really update.

just cache the position so no funny business happens

``````local bodySom = Instance.new("BodyGyro", script.Parent)
bodySom.Name = "wheelie"

local Cframe = script.Parent.CFrame

while true do wait()
local value = 45 * Cframe.LookVector.Magnitude

end
``````

https://gyazo.com/4264d015d804d2e4897a78ed731584be.mp4

2 Likes

It Works! but it doesnt really update where the it suppose to be facingâ€¦

I figured something else.

``````local bodySom = Instance.new("BodyGyro", script.Parent)
bodySom.Name = "wheelie"

local UpDir = Vector3.new(0,1,0)

while true do wait()
local Cframe = script.Parent.CFrame
local LookVector = -Cframe.RightVector:Cross(UpDir)
local value = 45 * LookVector.Magnitude

if you want to make it accurate on steep surfaces just change the `UpDir` with the `ray.Normal` of a ray with direction -Y (aka `workspace:RayCast(script.Parent.Position, Vector3.new(0,-5,0))`