How do i make a part rotate in the direction where a reference part is facing?

Sounds complex but hear me out.
so there is a car, and the wheels rotate normally when faced foward…

But when you turn… the wheel want’s to flip over (cuz the angular velocity is relative to the world)

So how can i change this so it knows where to rotate (according to a reference part which is the base of the vehicle)?

I think you can use VectorToObjectSpace method from CFrame
A:VectorToObjectSpace(Velocity)

My current method is using plane of rotation:

local Velocity = Vector2.new(0, 1)
local Wheel = workspace.Wheel

local _, Theta = Wheel.CFrame:ToEulerAnglesYXZ() Theta = Theta%(math.pi*2)-math.pi

Wheel.Velocity = Vector3.new(Velocity.X*math.cos(Theta)+Velocity.Y*math.sin(Theta), 0, Velocity.Y*math.cos(Theta)-Velocity.X*math.sin(Theta))

Idk if it can be simplified

1 Like

just checked (was playing phantom)
buuuuutt… i’ll try and get back
thx

can i get a briefing to what’s going on here btw?

Okay, I just get the X angle of the CFrame and use plane of rotation for relative velocity, that’s all. I think it should work, I tested it in studio.

Yep, it’s a bit complex, idk if there’s a better way. There’s the article of Plane of Rotation:

so it just looks complex… and is kinda… but the concept is simple

Hmmm…
Okay thx.
marked as solution, and thank you for your time. :grinning:

1 Like

i̶ ̶j̶u̶s̶t̶ ̶r̶e̶a̶l̶i̶s̶e̶d̶.̶.̶.̶ ̶t̶h̶i̶s̶ ̶i̶s̶ ̶v̶e̶l̶o̶c̶i̶t̶y̶ ̶a̶n̶d̶ ̶n̶o̶t̶ ̶a̶n̶g̶u̶l̶a̶r̶ ̶v̶e̶l̶o̶c̶i̶t̶y̶
nvm

Then do this, if the rotation of the part changes you should update it:

local Velocity = Vector2.new(1, 0)
local Wheel = workspace.Wheel

local _, Theta = Wheel.CFrame:ToEulerAnglesYXZ() Theta = Theta%(math.pi*2)-math.pi

Wheel.AngularVelocity.AngularVelocity = Vector3.new(Velocity.X*math.cos(Theta)+Velocity.Y*math.sin(Theta), 0, Velocity.Y*math.cos(Theta)-Velocity.X*math.sin(Theta))
1 Like

it just jitters araund (this might be a misuse of this)


the first method was unstable but it moved fine but steering was a mistake :grinning: