Move To disrupted by Destroy behavior

Hi all, I'm new to this. I've read the cookbook and searched through this forum pretty thoroughly but cannot find a solution to my problem. I apologize if I over-explain or misword something and most of all for asking stupid questions.

I have a basic setup with an actor (Hero) being controlled by keyboard arrows. He has a Collision Condition that spawns an actor (dead Hero) and invokes the Destroy behavior upon overlap with the Enemy actor.

I have the Enemy actor behaving with a simple Move To that carries him toward the Hero. It also has a Constrain Attribute behavior that keeps it facing the direction of travel. There are a few obstacle actors in the way, but that is the gist of it.

All the physics of both Enemy and Hero actors are set to 0.

This is what happens:
On Preview, the Enemy actor follows the Hero actor until it collides with him, spawning the dead Hero, and destroying the Hero. On collision, the Enemy actor immediately whips around and head to the bottom left hand corner of the screen.

I would like for the Enemy actor to maintain linear velocity and carry it through the (destroyed) Hero actor regardless of position or path of approach. I've turned off and on various rules until I found that the Destroy behavior on the Hero actor was a factor in sending the Enemy actor on a wild tangent. Shutting it off caused the Enemy actor to pause above the destroyed Hero Actor, which makes sense to me. With the Destroy behavior turned off, I attempted to get the Enemy actor to continue on its path after collision with Hero. I added various behaviors to the Enemy actor like Move, Move To, and Change Velocity and wrapped them in a Collision Condition so they would become active upon overlap with the Hero actor, but none of them seem to be working properly.

Any help would be greatly appreciated! All I'm hoping for is a rule that makes the Enemy actor move toward and through the Hero actor, destroying him in the process.

Comments

  • ImNiklasImNiklas Member Posts: 103

    This problem has many solutions, but the way I would do it like this; Inside the enemy actor, have a rule like this:

    When gameOver is false
    --Constrain Attribute self.directionToMove(angle attribute) to vectorToAngle(game.playerX-self.position.x, game.playerY-self.position.y)

    Under that you should have a move behaviour that tells it to move in the direction of that attribute.

    Before destroying the actor when it collides, you should change game.gameOver to true, but you probably figured that out already ;)

    Good luck!

  • lecasm2lecasm2 Member Posts: 3

    Ah man, it took me a while but I got it working. Thank you!

Sign In or Register to comment.