I want to make the character rotate to the mouse but never in the negative y axis and also make a limit on how far I can rotate my character to the positive y axis
I have tried looking at other posts but I have no idea how to edit them to how I want it to
Can you send a video of what is happening & the code that you are using?
You can limit it by using math.clamp()
.
You may read about it here.
1 Like
local RunService = game:GetService(“RunService”)
local player = game.Players.LocalPlayer
local character = script.Parent
local primary = character.PrimaryPart
local mouse = player:GetMouse()
mouse.TargetFilter = character
local bodyGyro = Instance.new(“BodyGyro”)
bodyGyro.Parent = primary
bodyGyro.D = 40
bodyGyro.P = 10000
bodyGyro.MaxTorque = Vector3.new(4000000, 4000000, 4000000)
while true do
local mousePos = mouse.Hit.Position
local primaryPos = primary.Position
local lookatPos = Vector3.new(mousePos.X, math.clamp(mousePos.Y, 0, 20), mousePos.Z)
bodyGyro.CFrame = CFrame.new(primaryPos, lookatPos)
RunService.Heartbeat:Wait()
end
it now cant move at the positive y axis but can move at the negative y axis
robloxapp-20201216-1010247.wmv (1.6 MB)