9ive
(Official9ive)
1
Pretty much, I’m making a drifting game, and I’ve been trying to make a script to detect the angle between the camera and the player’s rotation.
It’s supposed to work like this:
Which it does
Until I rotate the player in the opposite direction:
I mean obviously, if the world angle changes to a negative, everything else will too.
But is there a way to get the angle between JUST the camera and player WITHOUT world influence?
This is my code:
local char = player.Character
local hrp = char:FindFirstChild("HumanoidRootPart")
local cam = game.Workspace.CurrentCamera
game:GetService("RunService").RenderStepped:connect(function()
local swingformula = (cam.CFrame.LookVector.X-hrp.CFrame.LookVector.X)*100
script.Parent.Frame.Backing.Needle.Rotation = swingformula
print(swingformula)
end)
Thank you, and I’m sorry if this is an awful post. (It’s my first)
1 Like
koziahss
(Agent_Invalid)
2
Hmm are you looking for CFrame:VectorToObjectSpace()?
With that function you can calculate a direction relative to a CFrame.
You can then get the Characters LookVector relative to the Camera’s CFrame or Vice versa depending on how you want it to look.
Refer to Object and World Space | Roblox Creator Documentation
2 Likes
9ive
(Official9ive)
3
Thanks! I’ll give that a shot and let you know what happens!
Kind of irrelevant but this is related to CFrames
hmm = math.acos(u:Dot(v))
axis = u:Cross(v).Unit
qw = math.cos(hmm / 2)
qx = math.sin(hmm / 2) * axis.x
qy = math.sin(hmm / 2) * axis.y
qz = math.sin(hmm / 2) * axis.z
Just wanted to point it out!
1 Like
9ive
(Official9ive)
5
This worked PERFECTLY
Thank you!!!
This is the new code:
local swingformula = ((hrp.CFrame:ToObjectSpace(cam.CFrame)).X)
1 Like