Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How would I rotate the player with the mouse?

I am not asking for a script just a push in the right direction. Any help would be appreciated.

1 answer

✓ Accepted answer

Heading, Attitude, and Bank

These three terms each describe a certain value that describes the rotation. The technical name is YXZ intrinsic euler angles, but all you need to know is that Heading is the Y axis of rotation, Attitude is the X axis of rotation, and Bank is the Z axis of rotation.

A simple google image search will help a lot in terms of visualizing what each of these axes of rotation entail.

For calculating these values on Roblox, the wiki has a very good page that explains how to obtain and use the values.

How This Helps You

You can utilize these values in order to calculate the rotation needed for the torso of the player based on the Hit CFrame of the mouse.

Example:

local torsoCFrame = character.Torso.CFrame
local mouseCFrame = mouse.Hit
local _, _, _, _, _, m02, _, _, _, _, _, m22 = mouseCFrame:components()
local x, y, z, _, _, _, m10, m11, m12, _, _, _ = torsoCFrame:components()
heading = math.atan2(m02, m22)
attitude = math.asin(-m12)
bank = math.atan2(m10, m11)

character.Torso.CFrame = CFrame.new(x, y, z)*CFrame.Angles(0, heading, 0)*CFrame.Angles(attitude, 0, bank)

This discussion is preserved as it was. New answers, comments, and votes are closed.