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

How do I Make Doom-Like Sprite Rotation Work During Movement?

Asked by 4 years ago
Edited 4 years ago

I've gotten a sprite to turn like a doom model pretty easily using CFrame https://imgur.com/a/CezQ6Zz

The entire script used to make the Sprite turn towards the player:

local EnemyFolder = game.Workspace.Enemies
local PlayerTorso = game.Players.LocalPlayer.Character:WaitForChild("Torso")

--This function is used to make only the X and Z rotate
function rotateYaxis(originalPos, lookAtPos)
    return CFrame.new(originalPos,Vector3.new(lookAtPos.X,originalPos.Y,lookAtPos.Z))
end

--I use a for loop so I can have many enemies rotate with no further scripts
while wait() do
    for i,EnemyGot in pairs(EnemyFolder:GetChildren()) do
        EnemyGot.Enemy.Screen.CFrame = rotateYaxis(EnemyGot.Enemy.Screen.Position, PlayerTorso.Position)
    end
end

My problem is when adding "AI" to the model to move the model, the server side orientation overrides the client side, making it jitter between looking towards the player and the direction of where the model is moving.

Also, it seems my localscript is sometimes changing the orientation of the model on the server, I didn't know it could interact with the server, which is also messing more things up.

Is there any way I can fix these problems I face?

Answer this question