I'm making an item drop system that clings items to the floor, even on slopes. It works well, but it drops them perfectly in line and that can look odd.
local Drop = game.Workspace.Drop local Ray = Ray.new(Drop.Position,Vector3.new(0,-1,0)*50) local Hit,Pos = game.Workspace:FindPartOnRay(Ray) Drop.CFrame = CFrame.new(Pos)*CFrame.new(0,Drop.Size.Y/2,0)* CFrame.fromEulerAnglesXYZ(math.rad(Hit.Rotation.x),math.rad(Hit.Rotation.Y),math.rad(Hit.Rotation.z)) --Drop.CFrame = CFrame.new(Pos)*CFrame.new(0,Drop.Size.Y/2,0)* --CFrame.fromEulerAnglesXYZ(math.rad(Hit.Rotation.x),math.rad(math.random(0,90)),math.rad(Hit.Rotation.z))
As you can see, in order to give it some variation on how it's angled on the slope, I adjust the Y value to a random radian. This also works well, until I use it on a slope with a bunch of rotation values.
Watch, go into studio and make a part with a rotation of 0, 0, -30.
Now grab the green axis with the rotation tool and rotate it. Notice that x,y,z all change, instead of just y. The rotation tool automatically adjusts the others to it maintains it's previous orientation.
If anyone has the code that the rotation tool uses ( the formula to be exact ) so I can use it to rotate the "green axis" of a part while adjusting the others automatically, I'd be very pleased.