Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (601)
Games in Android Showcase (171)
games submitted by our members
Games in WIP (649)
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 1916 times)
0 Members and 1 Guest are viewing this topic.
Offline megabobik

Senior Newbie

« Posted 2011-11-01 20: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: 389
Projects: 3
Exp: 5 years

I'm the King!

« Reply #1 - Posted 2011-11-01 20: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 20: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: 88
Projects: 15


« Reply #3 - Posted 2011-11-01 20: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 Devvie

Medals: 5
Projects: 1

« Reply #4 - Posted 2011-11-01 21: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: 389
Projects: 3
Exp: 5 years

I'm the King!

« Reply #5 - Posted 2011-11-01 21: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.

Riven (24 views)
2015-07-27 16:38:00

Riven (14 views)
2015-07-27 15:35:20

Riven (19 views)
2015-07-27 12:26:13

Riven (9 views)
2015-07-27 12:23:39

BurntPizza (24 views)
2015-07-25 00:14:37

BurntPizza (36 views)
2015-07-24 22:06:39

BurntPizza (20 views)
2015-07-24 06:06:53

NoxInc (23 views)
2015-07-22 22:16:53

NoxInc (15 views)
2015-07-22 22:13:39

Jesse (36 views)
2015-07-22 03:10:36
List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21 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‑
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!