Using CFrame to rotate a part where another is facing

Hello… it’s me… again… with the same problem.
The short and sweet of it is that i want to rotate a wheel where a part’s “front” side is facing.
So far i am here. (but it is a mess and this is why i need help)

repeat
	local Velocity = Vector2.new(10, 0)
	local Wheel = workspace.Wheel
	
	local _, Theta = Wheel.CFrame:ToEulerAnglesYXZ()
	Theta = Theta % math.pi
	
	Wheel.BodyAngularVelocity.AngularVelocity = Vector3.new(Velocity.X*math.cos(Theta)+Velocity.Y*math.sin(Theta), 0, Velocity.Y*math.cos(Theta)-Velocity.X*math.sin(Theta))
	wait(.1)
until nil

The setup is: this script is in a part and the BodyAngularVelocity is in a cylinder in workspace named “Wheel”

If i need to rewrite the whole thing, that’s fine.

Are you able to provide a diagram to explain? Maybe a screenshot of the workspace with those parts in it?

And describe what doesn’t work about your current code. Does it point the opposite way? Is it out by 90 degrees? Etc

sure thing
one sec
(character limit)

original problem:
rotation is fine


but when you rotate it

AND NOW:
the problem is that i can’t find how on earth i calculate angular velocity relative to a part XYZ and not to world XYZ


So it rotates right the first time.


But when i rotate it, it doesn’t change the rotation’s direction
(can’t upload)

If you’re after relative angular velocity regardless of the vehicle’s orientation, you’ll find it much much easier to do this with constraints.

Here’s a quick demo place using constraints for the wheels of a vehicle:
DemoVehicle.rbxl (24.3 KB)

1 Like

OMG thank you.
A lot of people helped me in theese 2-3 weeks but this is going beyond.
Thank you for your time.

1 Like