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

How do I make a model face an enemy?

Asked by 8 years ago

I'm creating a tower defense game and need the towers to face the enemies so they can shoot them. I already have the magnitude and stuff made, I just need to know how to make the towers face the enemies.

Here's what I tried but it did not work:

turret.Center.CFrame = CFrame.new(turret.Center.Position, turret.Center.Position + enemy.CFrame.lookVector)

1 answer

Log in to vote
1
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
8 years ago
Edited 8 years ago

You're using the correct constructor (CFrame.new(position, lookAt)). You're just making it a bit too complicated.

That constructor automatically creates a CFrame at position, pointing towards lookAt. Therefore your solution is as simple as:

part.CFrame = CFrame.new(part.Position, enemy.Position)

The constructor does all the hard work for you.

0
Dear lord, I spent nearly an hour looking around the internet to find a solution to this. I can't believe it was this simple. Thank you! Chilling_Legacy 25 — 8y
0
:P User#11440 120 — 8y
Ad

Answer this question