Hello!
I was attempting to create a localscript
that spins your body towards your cursor, with animations (by changing animation.TimePosition
), and a number between 0, and 1. I have tried LookVectors
with the player's mouse, and it worked, but it wasn't the most efficient way to do it (it required a lot of trial and error to get the right number).
local cframe = game.Players.LocalPlayer:GetMouse().Hit local point = animpoint.Length local lookvector = cframe.LookVector --zvector? animpoint.TimePosition = ((math.clamp(lookvector.Y,-1,1)+1)/2)*point --usually results in a number ranging from 0 to 1 (0 being facing directly down and 1 facing directly up)
p.s. the code above also suffers from the camera's rotation and isnt particularly accurate
However, the problem is with the rotation towards the mouse for the torso (the code above refers to the rotation of the arms). I have tried everything, cframe:GetOrientation()
, cframe.LookVector.X
, cframe.LookVector.Z
, cframe.LookVector.X + cframe.LookVector.Z
, but it was all useless, because it didn't always point the cursor (the camera often affected it).
Is there a easier-to-figure-out alternative to the torso rotation?
tl;dr: how do i rotate the torso/arms towards the cursor using animation.timeposition or hopefully something easier to deal with
Hi, I tried to use bodyGyro to make the client face the cursor, however, it doesn't work perfectly and has room for improvement, yet, it's more reliable than servers physics.
game:GetService("RunService").RenderStepped:Connect(function() local forwardVector = (character.HumanoidRootPart.Position - mouse.hit.Position).Unit local rightVector = forwardVector:Cross(Vector3.new(0,1,0)) local cframe = CFrame.fromMatrix(character.HumanoidRootPart.Position, -rightVector, Vector3.new(0, 1, 0))
character.HumanoidRootPart.CFrame = cframe
end)
P.S. this code only adjusts the side orientation of the humanoidRootPart, it won’t make your character look up/down.
local cframe = game.Players.LocalPlayer:GetMouse().Hit local point = animpoint.Length local lookvector = cframe.LookVector local RoundedVector = math.floor(lookvector + 0.5)