Troubles with changing the orientation of a model... harder than you might think lol

I am trying to change the orientation of a model two different directions, however, it isn’t working. When i try to combine the two rotations (Rotation1 & Rotation2) into one line of code then the orientation of the model is able to change the orientation of the model to go slightly vertically (which i do not want), i only want the model’s orientation to change horizontally, if that makes sense? Any help would be greatly appreciated! :slight_smile:

Currently the script only changes the direction the model is facing upwards and downwards, however, i need it to also change the direction its turned sideways, if that makes sense? I do NOT want it to become vertical at all though. The reason i’m doing this is because i’m going to have like a hundred of these models and i want their orientations to be random so that the game doesn’t feel so static. i believe little changes in orientation of these models go a long way for the game feeling less “static” even though it’s such a small thing that players likely won’t think twice about.

Here’s the code:

while true do
	local PrimCFrame = script.Parent:GetPrimaryPartCFrame()
	local Rotation1 = CFrame.Angles(0,(math.random(-180, 180)),0)
	local Rotation2 = CFrame.Angles((math.random(-90, 90)),0,0)
	local RotatedCFrame1 = PrimCFrame * Rotation1
	local RotatedCFrame2 = PrimCFrame * Rotation2
	script.Parent:SetPrimaryPartCFrame(RotatedCFrame1)
	script.Parent:SetPrimaryPartCFrame(RotatedCFrame2)
	wait(3)
end

Here’s some examples of what i want the orientation to look like: (notice how they are all completely horizontal)



Here’s an example of what i do NOT want the orientation to look like: (notice how it is slightly vertical)

You could do the rotation on the X axis first then rotate on the Y, as that should keep the laid on its side appearance.

I agree the little details can make a big difference!

1 Like

That’s what i’m trying to go for in my current script, but it doesn’t work. I think what’s happening is that the second change for the X axis is overriding the first change for the Y axis because there are zeros in the Y & Z spots. However, i don’t know what to replace the zeros with so that they don’t change the axes to 0.

whats the point of having RotatedCFrame1 if it just gets overwritten by RotatedCFrame2, unless their supposed to combine then just have one RotatedCFrame equal to PrimCFrame* Rotation1*Rotation2.
Also use math.rad to turn the random numbers into number that will be compatible with cframe.Angles()

1 Like

Here’s the script now: (how would i implement using math.rad together with the math.random?)

while true do
	local PrimCFrame = script.Parent:GetPrimaryPartCFrame()
	local Rotation1 = CFrame.Angles(0,(math.random(-180, 180)),0)
	local Rotation2 = CFrame.Angles((math.random(-90, 90)),0,0)
	local RotatedCFrame = PrimCFrame * Rotation1 * Rotation2
	script.Parent:SetPrimaryPartCFrame(RotatedCFrame)
	wait(3)
end

EDIT: IT WORKS NOW!!! i had put the script in a loop for the sake of testing to see if the script works, however then i realized that the loop is actually the thing that makes it not work lol. Now that the loop has been removed and the script only runs ONCE at the beginning of the game, it works perfectly! Thank you to everybody who helped :slightly_smiling_face:

Here’s the final code:

local PrimCFrame = script.Parent:GetPrimaryPartCFrame()
local Rotation1 = CFrame.Angles(0,(math.random(-180, 180)),0)
local Rotation2 = CFrame.Angles((math.random(-90, 90)),0,0)
local RotatedCFrame = PrimCFrame * Rotation1 * Rotation2
script.Parent:SetPrimaryPartCFrame(RotatedCFrame)

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