Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago

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

Log in to vote
0
Answered by 3 years ago

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

Ad

Answer this question