Jump to content
  • Advertisement
Sign in to follow this  
VisualChaser

Creating an invisible circle for collision

This topic is 2170 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

As my first project I'm working on a tower defence game. The project is somewhere near 60% finished, including particles and all.
But I got stuck at coding the enemies and towers. I need an invisible circle that can be used to detect collision. If the enemy is in this circle (the circle is the range of the tower), the tower should start shooting. I also should be able to adjust the circle to the range of every tower, which can be upgraded. I already searched on some sites but I can't find a way to do this.
Can someone give me an example on how to do this?

Share this post


Link to post
Share on other sites
Advertisement
Your game is 2d ?
Then just take the distance, or square distance, between enemy and tower to determine if it is inside the effect radius:

for each enemy do
delta.x = enemy.x - tower.x
delta.y = enemy.y - tower.y
// square distance = dotProduct(delta,delta)
square_distance = delta.x*delta.x+delta.y*delta.y
// check if inside radius
if( square_distance <= (radius*radius) then
.. shoot at enemy
end
end
Edited by Ashaman73

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!