How to make part rotate on a relative axis?

Hello forum
I am having some trouble rotating a part relative to an axis.
I have gotten it to work with two separate axes (X and Z) but when the axes overlap, it causes strange behavior. The ball rotates on two axes at once.
Here is the current code

ball.CFrame = ball.CFrame   * CFrame.fromAxisAngle(Vector3.new(-lv.Z, lv.Y, lv.X), -math.rad(lookat))

(lv is the characters lookvector and lookat is the angle of rotation)

Thank you in advance

This doesn’t always work geometrically and only physically, but if I’m not mistaken there should be a constraint that a script can toggle. Sometimes they can be difficult to use though. I will try to fix your code in the best way I can however;

ball.CFrame = ball.CFrame * CFrame.fromAxisAngle(Vector3.new(-lv.Z, 0, lv.X), -math.rad(lookat))

All I did was toggle Y but I don’t know if that actually did anything. I apologize if this wasn’t helpful though.

Its the character lookvector, so the yaxis doesnt do anything. But what constaint are you talking about?

AlignOrientation or AngularVelocity. Now, I’ve never actually used these constraints. AngularVelocity should be in charge of rotation. However, AlignOrientation should be for locking alignments.

If you were trying to do something where the player or character looks at the ball, it rotates with it (sounds like what you are doing), then you might be able to use AlignOrientation on the Head and the Part.

But keep your code line commented and not deleted, because this may or may not work. (really, I don’t know)

I dont think that would work because the part is anchored

Could you give more information? possibly an image or video of what the ball is doing vs what it’s expected to do. The code line you posted really doesn’t tell anything.

fixed it by using the part’s orientation’s y axis (in a different script i use lookalong to keep ther part looking in the direction of the character’s lookvector)
Heres the new code:

	local o = ball.Orientation
			
    ball.CFrame = ball.CFrame  * CFrame.Angles(math.rad(-lookat), math.rad(o.Y), 0)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.