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

How would I rotate the player with the mouse?

Asked by
AZDev 590 Moderation Voter
8 years ago

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

1 answer

Log in to vote
3
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
8 years ago

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)
Ad

Answer this question