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

[UNANSWERED] RootJoint Manipulation (?)

Asked by
Nymint 85
9 years ago

Been experimenting with CFrame and attemting to learn more about trigonometry, I still don't get what sin, cos, and tan does, these three functions are wonderful.. I hope I can figure out someday soon.

Anyways, since manipulating the Coordinates of the HumanoidRootPart's "RootJoint" can rotate the character at a desired angle, I am trying to rotate the character via the Z Angle relative to the mouse, so it looks like the character is looking at the direction the mouse is pointing at, just the Z axis angle, because if I put X and Y it would tilt like a freakin' maneuver plane.

This is my attempt, it works, but it's not accurate, it's slightly offset.. and i'd love to learn how to actually do it via math/trigonometry.

local p=game:GetService("Players").LocalPlayer local m=p:GetMouse()
repeat wait() until p.Character local c=p.Character
local t=p.Character:WaitForChild("HumanoidRootPart")
local Root=t:WaitForChild("RootJoint")

m.Move:connect(function()
local CF=CFrame.new(t.Position,m.Hit.p):toObjectSpace(t.CFrame*Root.C0)
local _,_,_,_,_,_,_,_,_,x,y,z=CF:components()
Root.C1=CFrame.Angles(math.rad(-90),0,math.rad(180))
*CFrame.Angles(0,0,math.atan2(math.cos(z)*math.sin(x),math.sin(y))) end)

Professional help is greatly appreciated, thank you!

0
I'm not quite sure what you mean by it's offset, looks to me like it works fine... BlackJPI 2658 — 9y
0
It has a slight miscalculation of some sort, when you hold your camera and rotate your mouse around your character, you'll see the way it spins or "looks" at the mouse relative is faster than normal Nymint 85 — 9y
0
What I mean is, it's not exactly looking towards the mouse when facing a certain direction, it's slightly offset. Nymint 85 — 9y
0
Ohh okay, now I see it. I'm not quite sure how to fix it however :/ BlackJPI 2658 — 9y

Answer this question