Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I rotate the torso using animations?

Asked by
RAFA1608 543 Moderation Voter
3 years ago
Edited 3 years ago

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

2 answers

Log in to vote
1
Answered by 3 years ago
Edited 3 years ago

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.

0
This... isn't really what I was looking for, but thanks anyway. I'll try this. RAFA1608 543 — 3y
Ad
Log in to vote
-1
Answered by 3 years ago
local cframe = game.Players.LocalPlayer:GetMouse().Hit
local point = animpoint.Length
local lookvector = cframe.LookVector
local RoundedVector = math.floor(lookvector + 0.5)
0
Uh, what does this do? RAFA1608 543 — 3y
0
Did you even read what I am having trouble with? RAFA1608 543 — 3y

Answer this question