Collisions with region continue to be detected even after an actor exits region

oripessach

  • *
  • Posts: 259
I'm trying to implement a region that I can place and size in the scene editor, so that when my player enters it he gets blown upwards. This is the code - it creates a region that overlaps with the actor representing the region, and then hides the actor.

In the Updated event, I iterate over all the actors inside the region, and apply a force to them. This can be used to implement windy areas in the level, and those areas can be turned on and off. Pretty neat.

Except that it doesn't work. Once the actor enters the region, getActorsInRegion() continues to return that actor even after it gets blown out of the region.

What's going on here?

I'm attaching the code block images, if they're easier for some people to read.


Code: [Select]
override public function init()
{

/* ======================== When Creating ========================= */
createBoxRegion(ScaleUtils.scaledCoord("x", actor), ScaleUtils.scaledCoord("y", actor), ScaleUtils.scaledSize("width", actor), ScaleUtils.scaledSize("height", actor));
trace("Region creatd at (" + ScaleUtils.scaledCoord("x", actor) + ", " + ScaleUtils.scaledCoord("y", actor)  + ", " + ScaleUtils.scaledSize("width", actor) + ", " + ScaleUtils.scaledSize("height", actor)+")");
_Region = getLastCreatedRegion();
propertyChanged("_Region", _Region);
actor.disableActorDrawing();

/* ======================== When Updating ========================= */
addWhenUpdatedListener(null, function(elapsedTime:Float, list:Array<Dynamic>):Void
{
if(wrapper.enabled)
{
for(actorInRegion in getActorsInRegion(_Region))
{
if(actorInRegion != null && !actorInRegion.dead){
if(!(actorInRegion == actor))
{
trace("" + actorInRegion);
actorInRegion.push(_X, _Y, _ForceMagnitude);
}
}
}
}
});

}

yoplalala

  • *
  • Posts: 1632
I'm seeing "scaled x of self" . What is the origin point of the actor ? Is it at the centre or not ? ( I think it works only if the origin point is at the centre)
Have you put debug drawing, to see if your actor is really outside of the region ?

oripessach

  • *
  • Posts: 259
Oh, the actor is definitely outside the region. In fact, because of this issue, it goes completely off the screen.

I think this happens because a cast error somewhere else that causes the engine to skip doing something it needs to do.