How to make something "look" at another thing

Hey! So im making a tds game and im working on the tower shooting system

And i need to make so the towers rotate to look at the zombies they are shooting

Could anyone help me on how to do that?

This should work:

tower:SetPrimaryPartCFrame(tower.PrimaryPart.Position, enemy.PrimaryPart.Position)

Also, this will rotate the entire model, so if they aren’t on the same Y level then it could look a little weird

2 Likes

You should use the Object’s CFrame | Roblox Creator Documentation.

Every CFrame has two components which are vector3 objects, a positional and rotation component.

To make a CFrame which looks in a direction:

CFrame = CFrame.lookAt(TowerPosition, ZombiePosition)

CFrames are one of the most important aspects to learn about in Studio, so I recommend reading CFrames | Roblox Creator Documentation

Oh so CFrame also interfers at rotation, interesting

Thx! ima read more about CFrames later!

Anytime. If either of us helped and answered your question consider marking one of our posts as a solution for future readers wondering the same thing you are. Cheers.