Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (576)
games submitted by our members
Games in WIP (497)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Check colliding 1 unit with another  (Read 1632 times)
0 Members and 1 Guest are viewing this topic.
Offline megabobik

Senior Newbie





« Posted 2011-11-01 21:37:11 »

Hey people , i need your help .

I am making RTS i have 1 problem : how to check if 1 unit is colliding with another unit.

Give me idea  how to solve this problem.

Thnk you.
Offline ra4king

JGO Kernel


Medals: 322
Projects: 2
Exp: 4 years


I'm the King!


« Reply #1 - Posted 2011-11-01 21:47:44 »

Depending on the shape of the unit, you could do a rectangle vs. rectangle or a circle vs. circle collision check. These are the most basic ones to use.

Offline megabobik

Senior Newbie





« Reply #2 - Posted 2011-11-01 21:49:58 »

rectangle vs rectangle
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline kappa
« League of Dukes »

JGO Kernel


Medals: 70
Projects: 15


★★★★★


« Reply #3 - Posted 2011-11-01 21:51:16 »

normally in RTS games the collision is handled by the path finding algorithm (A*, Dijkstra's, etc) so its handled by some sort of grid. Other options are to use some sort of flocking algorithm or steering behaviour.
Offline gbeebe

Senior Member


Medals: 5
Projects: 1



« Reply #4 - Posted 2011-11-01 22:00:48 »

When I was doing something like this, I had an array that represented the map divided up into little sections (or tiles/ or something smaller than tiles).  Each unit, when moving, "owned" 2 indexes in the array (the one it was on, and the neighboring one it was headed to).  The indexes were marked by the ID's of the units on them or moving to them.  When the unit reached the destination index, the previous index was set to zero, and then it check to see if the next index was available (available = 0), if it is available it marks it with it's ID and heads towards it... etc.  Units could not collide because they would first check to see if the index that it wanted to move to was available, if not it would either wait or find an alternate route.
Offline ra4king

JGO Kernel


Medals: 322
Projects: 2
Exp: 4 years


I'm the King!


« Reply #5 - Posted 2011-11-01 22:04:55 »

For recangle vs. rectangle, you can use java.awt.Rectangle/java.awt.geom.Rectangle2D.Double and use their intersects(...) method or build your own intersects method.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (15 views)
2014-04-15 18:08:23

BurntPizza (13 views)
2014-04-15 03:46:01

UprightPath (27 views)
2014-04-14 17:39:50

UprightPath (12 views)
2014-04-14 17:35:47

Porlus (29 views)
2014-04-14 15:48:38

tom_mai78101 (51 views)
2014-04-10 04:04:31

BurntPizza (110 views)
2014-04-08 23:06:04

tom_mai78101 (211 views)
2014-04-05 13:34:39

trollwarrior1 (179 views)
2014-04-04 12:06:45

CJLetsGame (185 views)
2014-04-01 02:16:10
List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:05:20
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!