Two entities collide. One of them should move out of the way


(John Andersson) #1

Only one of the colliding entities should move, and which entity should move should be random

I tried doing this

var collide_d:Dan = collide("dan", x, y) as Dan;
if (collide_d && doOneTime == 1)

{ var whom:int = FP.choose(1, 2); if (whom == 1) y -= 40; if (whom == 2) collide_d.y -= 40; doOneTime ++; }

Now there is one problem. When both Dan entities collide, they both run this function. If they both happen to get the same value of whom, they both move.

How do I counter this problem? I thought I’d handle all of this inside of the gameworld, but I don’t know how to check if two external entities collide…

Thanks


(Martí Angelats i Ribera) #2

I feel like i needs a more deep explanation. What is your project about (no need for a detailed explanation) and what’s the effect you want to get.

Even doe, i’d say that what you want is something like (again i have no real code to support this so it feels more like an hypothesis than a real solution)

var collide_d:Dan = collide("dan", x, y) as Dan;
if (collide_d && !collided && doOneTime == 1)
{
collide_d.collided = true;

var whom:int = FP.choose(1, 2);
if (whom == 1) y -= 40;
else collide_d.y -= 40;

doOneTime ++; 
}

//where collided is a boolean that every custom entity have.