Dusk's tile culling and moving enemies

Hello Caleb!

 

I just made a moving enemy object with physics. Everything works fine, until the enemy (child object from your addObjectType function) goes off screen. Obviously enemy falls because of tile culling destroys the floor where it is walking  :smiley:

 

I don’t want the tile culling disabled, so I was thinking 2 options:

 

  1. Set gravity off when enemy(child object) off screen. 

Question for this option: is there a method to check if child object is off screen? 

 

  1. Modify the starting and ending points for tile culling (in a specific tile layer would be nice).

Question for this option: how do I do that?

 

Or do you have much better method for this?  :slight_smile:

I recommend…

  1. Your gravity idea. Why can’t you completely turn gravity off on the object?

  2. Use a weld or touch joint and move the source to keep the enemy where you want it (obviously, complex enemies who can jump and climb wouldn’t be doable with this). This would be equivalent to gravity, just a different approach.

  3. Add a floor underneath the enemy when it’s created as part of the addObjectType build function.

I think the floor option will be the most robust. All you need to do is create a little rectangle, add physics, and remove when the object’s removed. This could all go in your object type function and count as one object - enemy and floor.

Also, if you haven’t already, you should probably make your enemy-building object type use a “patrol rectangle” - instead of a single rectangle for where the enemy is, use a wide rectangle to define how far the enemy can patrol goomba-style. That way, culling will be guaranteed to only activate when the enemy is offscreen, whereas if you create a single rectangle and the enemy walks onscreen when the rectangle is offscreen, the enemy will be obviously and ugly-ly deleted.

  • Caleb

The enemy would just fly  if the gravity is turned off… Also it jumps when there is obstacle in front of it so I really need the gravity   :smiley:

I was thinking if I check the x and y distance between player and the enemy in the enemy’s enterFrame function and set the gravity off when difference > display.contentWidth*0.5 or display.contentHeight*0.5. 

I am actually using the wide rectangle to define the area where it  “patrols” :slight_smile:

I received some more information via PM which changes things a bit. Can we continue this in PM?

  • Caleb

For anyone reading this and wondering about the same problem, the solution ended up being that @Painconfess was using an in-house physics engine I wrote for them, and I updated the engine to support offscreen physics.

For people using Box2D for their physics, I recommend the extra floor approach, because it gives the most flexibility but is still easy to implement.

  • Caleb

I recommend…

  1. Your gravity idea. Why can’t you completely turn gravity off on the object?

  2. Use a weld or touch joint and move the source to keep the enemy where you want it (obviously, complex enemies who can jump and climb wouldn’t be doable with this). This would be equivalent to gravity, just a different approach.

  3. Add a floor underneath the enemy when it’s created as part of the addObjectType build function.

I think the floor option will be the most robust. All you need to do is create a little rectangle, add physics, and remove when the object’s removed. This could all go in your object type function and count as one object - enemy and floor.

Also, if you haven’t already, you should probably make your enemy-building object type use a “patrol rectangle” - instead of a single rectangle for where the enemy is, use a wide rectangle to define how far the enemy can patrol goomba-style. That way, culling will be guaranteed to only activate when the enemy is offscreen, whereas if you create a single rectangle and the enemy walks onscreen when the rectangle is offscreen, the enemy will be obviously and ugly-ly deleted.

  • Caleb

The enemy would just fly  if the gravity is turned off… Also it jumps when there is obstacle in front of it so I really need the gravity   :smiley:

I was thinking if I check the x and y distance between player and the enemy in the enemy’s enterFrame function and set the gravity off when difference > display.contentWidth*0.5 or display.contentHeight*0.5. 

I am actually using the wide rectangle to define the area where it  “patrols” :slight_smile:

I received some more information via PM which changes things a bit. Can we continue this in PM?

  • Caleb

For anyone reading this and wondering about the same problem, the solution ended up being that @Painconfess was using an in-house physics engine I wrote for them, and I updated the engine to support offscreen physics.

For people using Box2D for their physics, I recommend the extra floor approach, because it gives the most flexibility but is still easy to implement.

  • Caleb