The Daily Click ::. Forums ::. Klik Coding Help ::. Moving around objects/bg (with vector movement?)
 

Post Reply  Post Oekaki 
 

Posted By Message

SolarB



Registered
  26/12/2011
Points
  564
18th January, 2012 at 17:40:15 -

Ok so I'm making pretty good progress with an RTS style game, even though some of the coding is a tad (ahem) inefficient. Found Sketchy's RTS movement example (the one with all the crazy calcs and neat coding) and would like to know if this could be expanded on with some pathfinding - preferably without using any of the PF extensions.

Also played the Terminal Orbit demo and noticed that the pathfinding in that used some kind of collision detection + angle/direction rotation. How is this done for so many units and so smoothly??

Best I can figure is (roughly):

+Always
--> set angle (calc for angle) of unit to target
+Always
--> (clickteam movement object) set direction to angle(unit)
+Collision with obstacle
--> set angle(unit) to angle(unit)+?


Alternatively, if anyone could please upload the Terminal Orbit source I would be most grateful, I'm dying for a chance to analyze the bejeezus out of this game! Otherwise I'll buy the Klikdisc with it but I'd rather not as I'm not really interested in the other stuff on it and I'm not even sure it still exists.

Thanks!

 
My Open Source Examples: http://bit.ly/YyUFUh

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1970

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
18th January, 2012 at 18:54:06 -

Re: The RTS movement example - for those who haven't seen it, I presume he means this:
https://skydrive.live.com/redir.aspx?cid=b1e7ee094271bbda&resid=B1E7EE094271BBDA!489&parid=B1E7EE094271BBDA!131

I know nothing about Terminal Orbit or how it was made, so can't really help with that.
The method you suggested could work for navigating around very simple obstacles, like an individual tree/rock for example - but you really need something far more sophisticated (probably an extension) to navigate around more complex obstacles, without getting stuck or taking a stupidly indirect route.

 
n/a

SolarB



Registered
  26/12/2011
Points
  564
19th January, 2012 at 08:28:50 -

Trawling through everything on TDC, found this tute:

http://www.create-games.com/article.asp?id=2120

I think this could be adapted somehow, still trying to get my head around it.


Cheers.

 
My Open Source Examples: http://bit.ly/YyUFUh

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1970

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
19th January, 2012 at 15:59:29 -

That's an interesting article, and he has some very nice example files there too.
In terms of simply getting units from A to B, it's not going to be any better than just using detectors to avoid obstacles - it's still not going to be able to handle anything more complex than small individual obstacles, and it will require a lot more calculations too (could get very slow with large numbers of units and obstacles).
The advantage is that units could seem to have greater awareness of their surroundings, and so might appear to behave more intelligently / realistically.
I'd say if in doubt, go with the simpler option first...

If you just want dumb AI, where the player has to babysit his units (this was actually pretty common with early RTS games) or if you're prepared to make your map design *very* simple, then either method would be okay (maybe just add waypoints as well).

If you want smart AI, where the player just has to tell units where to go, and they get there by themselves, then I think you absolutely must use a pathfinding extension - no other method will allow units to plan far enough ahead to avoid getting stuck.

 
n/a

SolarB



Registered
  26/12/2011
Points
  564
19th January, 2012 at 17:19:03 -

Scenario:
1. Units are placed on one side of a mountain.
2. Player selects units and clicks (places target) on the other side of the mountain, exactly west of the units.
3. Units move to the target, and on collision with the mountain set their angle/direction + or - (still don't know how to pick) their current angle/direction. Having navigated around the mountain they set their heading towards the target.

Units don't have to plan, they just have to avoid the obstacle. Also, my map is too big for even the APF extension to handle (I think).

Using the method in my first post I've managed to get units to go around objects of 256x256 relatively well in a test, but still no dice when put into the actual game. Detectors are at this stage unfortunately not an option.

If you look at the TO demo this is done very well and it doesn't look like PF to me. Also in the tank example from my second post I can see how it could work for large obstacles - I've tried to simplify my code using those example files but the complexity of these (at least to me) is doing my head in.

If a simplified version of this to suit my needs could be done I would be ecstatic.

Cheers.

 
My Open Source Examples: http://bit.ly/YyUFUh

SolarB



Registered
  26/12/2011
Points
  564
19th January, 2012 at 17:23:40 -

...So as per the tank example all the obstacle has to do is give the unit a little 'push'...

 
My Open Source Examples: http://bit.ly/YyUFUh

SolarB



Registered
  26/12/2011
Points
  564
19th January, 2012 at 17:33:47 -

Sorry for posting again...

A link to my quick and dirty example file:

http://www.mediafire.com/?onbvkn684zfnq11


Not perfect, but workable.

 
My Open Source Examples: http://bit.ly/YyUFUh

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1970

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
19th January, 2012 at 18:57:53 -

Detectors are always an option - just make them embedded:
https://skydrive.live.com/redir.aspx?cid=b1e7ee094271bbda&resid=B1E7EE094271BBDA!490&parid=B1E7EE094271BBDA!131

 
n/a

SolarB



Registered
  26/12/2011
Points
  564
20th January, 2012 at 05:52:41 -

Looks good, thanks!

 
My Open Source Examples: http://bit.ly/YyUFUh

SolarB



Registered
  26/12/2011
Points
  564
20th January, 2012 at 17:18:09 -

Hey Sketchy,

Great job, if this project ever sees the light of day you'll be the first credited. However now I have a problem - sometimes the units get stuck in a loop going around and around the obstacle until they receive another target, even if they are close to the one that was set. Any fixes?


(PS: got a copy of the Terminal Orbit source... looks like a similar method to Cameron's. Not complaining, this is more than perfect for what I have right now.)

 
My Open Source Examples: http://bit.ly/YyUFUh

Jenswa

Possibly Insane

Registered
  26/08/2002
Points
  2722
20th January, 2012 at 17:35:36 -

@Noodles,

not sure what your unit is doing, walking in a circle around the same obstacle? Some pics with info of the situation would help. But if the unit is walking a certain position over and over it might have something to do with the number pixels it's walking with. Because it can step over the target and then step back and step over the target once more while going back.

However I've no knowledge of your engine's internals, so I am just guessing what could be going on.

Hope this helps you a bit.

 
Image jenswa.neocities.org

SolarB



Registered
  26/12/2011
Points
  564
20th January, 2012 at 17:53:08 -

@Jenswa,

Pretty much the same internals as Sketchy's example above, same issue there so grab that. In the game, select a bunch of units and click on a point in between or just below some obstacles (make a block of them as a good test). You'll see one or two of the units just go round and round. Move target is computed based on angle/distance stored in alts, seems to work perfect unless the collision events are running (it seems).


@Sketchy,

Just want to mention I had to move the distance calc below the collision calcs in order to set a separate 'moving' animation as opposed to just the 'selected' one.


Cheers

 
My Open Source Examples: http://bit.ly/YyUFUh

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1970

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
20th January, 2012 at 18:53:54 -

Units only stop when they get within 10 pixels of their destination. If there's an obstacle stopping them getting within 10 pixels, they will just keep walking.
You could always add a line to check if the unit is within 40(?) pixels, and getting further away - and if so, stop walking.

Units will also start walking around in circles if they encounter a concave obstacle, but that would require proper pathfinding to fix.

 
n/a

SolarB



Registered
  26/12/2011
Points
  564
20th January, 2012 at 20:31:08 -

No dice.

Set a flag for when the distance is first <40, then checked if flag was on and distance was >40. Unit goes merrily around ignoring his destination until another is set. Also, there can't be an obstacle other than the backdrop stopping him since he goes through them. Could it be the arrangement formula? Also could it be the stop calc is ignored if he's overlapping the obstacle? Check out your egx and let me know.

 
My Open Source Examples: http://bit.ly/YyUFUh

SolarB



Registered
  26/12/2011
Points
  564
20th January, 2012 at 20:46:59 -

EDIT -- Ok I got it to work using a totally patch-up way. Still want to hear your thoughts...

 
My Open Source Examples: http://bit.ly/YyUFUh
   

Post Reply



 



Advertisement

Worth A Click