Jump to content

View more

Image of the Day

Inventory ! Va falloir trouver une autre couleur pour le cadre D: #AzTroScreenshot #screenshotsaturday https://t.co/PvxhGL7cOH
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Creating an invisible circle for collision

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
2 replies to this topic

#1 VisualChaser   Members   

382
Like
0Likes
Like

Posted 15 June 2012 - 01:27 AM

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?



#2 Ashaman73   Members   

13714
Like
1Likes
Like

Posted 15 June 2012 - 03:42 AM

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, 15 June 2012 - 03:42 AM.

Ashaman

 

Gnoblins: Website - Facebook - Twitter - Youtube - Steam Greenlit - IndieDB - Gamedev Log


#3 VisualChaser   Members   

382
Like
0Likes
Like

Posted 15 June 2012 - 11:33 AM

Yes that should work. But in C++ the script would be even easier I think, I'll figure something out. Thanks!




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.