Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

My model is incorrectly orientated, How do i rotate it with scripts?

As in the question i have this model that is incorrectly orientated to the enemy, It rotates at the wrong direction and shoots bullets at the opposite direction, i tried searching many methods how to fix this but they all did nothing, So i wanna ask here how do i fix this problem.

1 answer

You can use trigonometry for this, use the X and Z axis, and with the usage of an imaginary triangle you can calculate its angle.

It would probably look something like this:


local angle = math.Atan2(enemyPos.Z - playerPos.X ,enemyPos.X - playerPos.X)

model.PrimaryPart.CFrame = CFrame.new(model.PrimaryPart.Position) * CFrame.Angles(0, angle, 0)

If this makes it reversed just try swapping the order of the variables inside of Atan2

This discussion is preserved as it was. New answers, comments, and votes are closed.