I am making object rotation where if you press R or T it will rotate the object. Now, currently I am using math.rad and multiplying Cframe.Angles to the hitpos (updates position every frame render) the issue is that the object is rotating globally and not locally, meaning that if you angle it with R to face left and try to move the object to rotate upwards, it will instead spin. Please Help.
please show the snippet of the script that manages rotation so that we can better diagnose the problem
make keep a rotated cframe separate from the hitpos, so when you want to rotate, rotate that cframe
then, whenever setting the cframe, set it to (hitpos * the rotated cframe)
Object:SetPrimaryPartCFrame(CFrame.new(HitPos))
^ renderstepped
v key presses
if not Processed and InputObject.KeyCode == Enum.KeyCode.R and Object then
RotationY += 22.5
elseif not Processed and InputObject.KeyCode == Enum.KeyCode.T and Object then
RotationX += 22.5
end
I can’t show too much in this.
are you doing it in a local script? anything you do on a local script only happens for the client.
Yes it’s a localscript. I am only doing it local so it doesn’t spam remoteevents until I really actually place it.
Perhaps renderstepped has something to do with it? what’re you using it for anyways. the way I would do it is just have it set the rotation everytime you press the key.
also is the object part of the character? what is the location of it?
It sets the cframe to the vector3 hitpos multipled by cframe.angle.
i feel like maybe the problem is renderstep, do you think you can do it any other way? because I know if you rotated it using vector3’s and such it should happen locally.
What are you using RenderStepped for? I think a ContextActionService:BindAction
would be enough. Or simply just UserInputService
. If you put the rotation in RenderStepped, of course it will spin, because you’re rotating it continuously.
yeah i was thinking UIS too. not sure what render is being used for here.
Not spinning as in constantly, I mean it doesn’t spin on the right axis.
Oh, I see. But you still don’t need to use RenderStepped. You can just set the primary part CFrame in the key pressed function. Could you show more of your code? What are RotationX
and RotationY
? How do you use them? What’s HitPos
? What’s Object
?
When you refer to positioning/rotating an object locally what you mean is positioning/rotating it relative to its own object space rather than the world space.
Object.CFrame = Object.CFrame:ToObjectSpace() * CFrame.Angles(math.pi, math.pi, math.pi) --change the values passed to the angles constructor