Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Keeping objects from overlapping

Author
Message
047
20
Years of Service
User Offline
Joined: 4th Jun 2006
Location:
Posted: 18th May 2014 00:12
Does anyone know a simple way to keep objects from overlapping? I've experimented using the collision command with limited success. For example, when two object collide I move one object left and the other right depending on their position in relation to each other. This method usually works when it's only two objects but when there's more than two objects it doesn't work well anymore. Does anyone know of a better way or have any simple suggestions that do not involve creating an entire AI system for each object. I have tried that approach too but was wondering if there is an easier way.
Thanks!
MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 18th May 2014 00:15
SET OBJECT COLLISION ON ObjNumber

?

wattywatts
17
Years of Service
User Offline
Joined: 25th May 2009
Location: Michigan
Posted: 18th May 2014 03:32
When you mention AI I'm wondering if you're talking about enemies? Your ideal approach would be to set up Sparky's collision or something similar, but in a pinch you could handle it different ways depending on what exactly you're working with.
GreenDixy
17
Years of Service
User Offline
Joined: 24th Jul 2008
Location: Toronto
Posted: 18th May 2014 07:00
you could check the distance between the objects and tell them to move away by x amount

.:: Http://DeanWorks.Ca ::.
My software never has bugs. It just develops random features.
047
20
Years of Service
User Offline
Joined: 4th Jun 2006
Location:
Posted: 18th May 2014 08:17
My issue is not with the collision command. The DBP built-in collision command works pretty well for me so Sparky's shouldn't really make a difference. What I'm really looking for is for example, if I want to create a game where several enemy objects coming from different directions are following the player object, eventually they may all meet at a certain point. So I was wondering if anyone has any ideas on how to keep the enemy objects from overlapping each other. The AI concept I was referring to is kind of what would happen in real life if several people where about to meet at one point. Some would have to stop so that the others would continue moving or maybe some would move left or right or back to allow room for the others, but unless they are ghosts they would never occupy the same space at the same time.
wattywatts
17
Years of Service
User Offline
Joined: 25th May 2009
Location: Michigan
Posted: 18th May 2014 10:04
Ok, so if there's a collision between enemies, just stop the ones further away until the closest one clears the path. There's some examples on the forum of how to determine object distance if you need help with that.
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 19th May 2014 15:52 Edited at: 19th May 2014 15:55
Quote: "if I want to create a game where several enemy objects coming from different directions are following the player object, eventually they may all meet at a certain point. "


The most effective way of handling this is to implement local awareness between enemies. A game I worked on used flocking, otherwise known as "boid simulation", and extensively made use of alignment so even though many entities had the same destination, they'd walk next to each other:



If you implement it correctly, you can add all sorts of cool stuff on top of it for free, such as object avoidance, or being able to locally search for detours when other entities block your path.

TheComet

Your signature has been erased by a mod
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 19th May 2014 18:15
@TheComet

Wow, it is TheComet. How are things? Any new work on that C++ version of your game?

Zero G Scott
18
Years of Service
User Offline
Joined: 14th Dec 2007
Location: California, USA, Earth, Sol Sys
Posted: 19th May 2014 21:31 Edited at: 19th May 2014 21:41
@TheComet

Whoa, that flocking link is a gold mine! Thank you for posting that!
Derek Darkly
14
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 19th May 2014 22:24
I came up with some slop based on distance checks, but that flocking concept seems a lot cleaner. I had trouble with separation. If anyone has a working DBP example of flocking it please post it!



666GO†O666
047
20
Years of Service
User Offline
Joined: 4th Jun 2006
Location:
Posted: 20th May 2014 03:17 Edited at: 20th May 2014 03:23
I applied wattywats idea and created a short test program that seems to work fine so far. Any suggestions to make the concept more efficient?

Login to post a reply

Server time is: 2026-07-08 10:39:39
Your offset time is: 2026-07-08 10:39:39