Safe Spawn Problem.

Monkey Forums/Monkey Programming/Safe Spawn Problem.

Paul - Taiphoz(Posted 2016) [#1]
Sup peeps...

So in a nutshell, I spawn powerups at a given x,y when something that drops a powerup dies, normally an alien cargo ship.

My issue is that if I happen to kill a ship that drops a powerup and an existing powerup happens to be under the ship then we get this overlap, player thinks he's picking one up and he's actually getting two..

at first I thought it would be a simple solution , just move the new powerup x pixels away from the existing one, which is fine for just two powerups but it's possible for them to spawn in clusters if the player happens to kill a number of things at the same spot at the same time, as each new power up spawns, and moves to avoid something it can end up moving into another..

Does anyone have any thoughts on this ?


Pakz(Posted 2016) [#2]
Here is a code example of dots which repulse from each other. If you look at this as if they were drops then they would end up not touching each other.

Maybe usefull for this situation.

http://monkeygameprogramming.blogspot.nl/2015/02/monkey-x-organic-behaviour-with-bots.html

I got it from a game ai book.


Gerry Quinn(Posted 2016) [#3]
Simple answer: give him both. Seriously, why not?


Paul - Taiphoz(Posted 2016) [#4]
Pakz that idea was one of the options I tried but in tests I had situations where it would pick a push north only to have that push land the powerup inside another powerup, if the wrong situation arose it could push quite far to one of the set directions leaving the new powerup no where near where it was supposed to have spawned it just looked odd.

Another solution I tried quickly was to have it pick a random direction -180,180 and then push out in that direction, this was a little better but still falls down when there are loads of powerups in a small tight area.

This fortunately is not a game breaking thing it's just me being a bit picky.


muddy_shoes(Posted 2016) [#5]
I'm not sure that Pakz is suggesting choosing a spawn point. I think he's suggesting implementing something that will move your pickups away from each other if they are overlapping. I've knocked up a simple example of what I think he means here: http://stickydesigns.com/pickups/MonkeyGame.html (click to drop a "pickup")


Paul - Taiphoz(Posted 2016) [#6]
Muddy two things, first of all that highlights the issue I was having if you don't move the mouse while clicking it fails to push the balls out or it will push them all out to the north or south or whatever which is what I do not want, I get that if I just move the mouse(spawn point a few pixels) while clicking it works as intended but there would still be a chance for those annoying situations to happen where one powerup covered another or where the pushed spawn point is way off from where it should be.


Paul - Taiphoz(Posted 2016) [#7]
Like I said tho I'm just being overly picky it's not an essential thing..


muddy_shoes(Posted 2016) [#8]
I'm not sure which part of "a simple example of what I think he means" was unclear. Clicking in the same spot is just a special case for the push calculation. It's easily fixed. As for the rest I've no idea what your specific usage is so I don't know what problems you're really talking about. There's no instance (once the special case above is fixed) where they would remain overlapped and they only have to move as far as needed to not overlap. Either overlapping is a problem you want to fix or you don't want to move them off the "real spawn point". You're going to have to pick one.

Again, I just thought I'd give you a simple example in action, I wasn't claiming to have written the exact solution for whatever you want to actually do. I'm not a mind-reader. Sorry if I wasted both our time.


Paul - Taiphoz(Posted 2016) [#9]
none of what you said was unclear I guess it was me being unclear, anyway thanks for posting that little example just spamming it a few times helped me realize the issue I had with my code probably is'nt something I really should be wasting time on as it's a bit of a non issue.

Posting my method bellow in case anyone else has an issue like this, all I am doing is looping through my objects comparing 1 to another and if their touching or overlapping I pass both objects to push to have them moved a little away from each other, results are more than good enough for my project, hope it helps some one else .

	Method Push:Void(_a:cPowerUp, _b:cPowerUp)
		Local dist:Float = emDistance(_a.pos.x, _a.pos.y, _b.pos.x, _b.pos.y)
		Local ang:Float = ATan2(_a.pos.x - _b.pos.x, _a.pos.y - _b.pos.y)
		Local dx:Float = Sin(ang)
		Local dy:Float = Cos(ang)
		_b.pos.x -= dx
		_b.pos.y -= dy
		_a.pos.x += dx
		_a.pos.y += dy
		_a.updateAngle
		_b.updateAngle
	End Method