Platformer enemy that follows the player? + Health bar for all enemies?

0 favourites
  • 8 posts
From the Asset Store
Basic Rounded Vector Geometry Player Design with Glow for 3 player games
  • I'm making a prototype 2D Arena Shooting game to show off to my friends but I want enemies to spawn that follow the player using the platformer collision/movement system to attack the player. I also need help getting a healthbar to work with all the enemies.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • For the enemies, here is a very simple AI:

    If Enemy.X > Player.X : Enemy -> Simulate Control -> Left

    If Enemy.X < Player.X : Enemy -> Simulate Control -> Right

    Note that this doesn't include jumping, which if you need I can help with that, just let me know.

    _________

    For the Healthbars, try:

    Enemy -> On created : Create Object -> Healthbar. Make sure that the position is Enemy.X, Enemy.Y-50 (Or change 50 to whatever is needed to position it properly), then Healthbar -> Pin to Object -> Enemy (Make sure those two actions are in the same event)

    If you need any more help or want me to create a mock-up and share it with you then let me know.

  • I think I understand, if I need help I'll come back.

  • Also what does pin to object do?

  • Pin is a behavior you can put on an object that will "pin" it to something else, so you can keep it at the same relative location.

    Here is the official manual entry for Pin

  • For the enemies, here is a very simple AI:

    If Enemy.X > Player.X : Enemy -> Simulate Control -> Left

    If Enemy.X < Player.X : Enemy -> Simulate Control -> Right

    Note that this doesn't include jumping, which if you need I can help with that, just let me know.

    _________

    For the Healthbars, try:

    Enemy -> On created : Create Object -> Healthbar. Make sure that the position is Enemy.X, Enemy.Y-50 (Or change 50 to whatever is needed to position it properly), then Healthbar -> Pin to Object -> Enemy (Make sure those two actions are in the same event)

    If you need any more help or want me to create a mock-up and share it with you then let me know.

    I got the movement code working but I need help individualizing the X and Y, I used to use scratch where the variables were automatically individualized. Also how do you even make a health bar.

  • What do you mean by individualizing? The "if Enemy.X > Player.X" already check the X of every individual instance of X. There isn't any need to make a unique variable for every enemy. Here's the manual entry on Object Instances. (I think there was a manual entry on intance selecting but I couldn't find it)

  • As for the health bar, create a Sprite and call it whatever you want (I'll be referencing it as HealthBar)

    (This method I am using will make a health bar that will shrink as the enemy loses health. There are ways to make it look better but this is the easiest)

    Make sure the origin point of HealthBar in the center.

    Add an instance variable to Enemy and HealthBar called "id". Add a global variable called idTracker.

    Make sure the enemies have an instance variable called "hp" and "maxHP". When an enemy spawns, set its hp and maxHP to whatever health it spawns with. When the enemy takes damage reduce hp but not maxHP.

    Then for events:

    Enemy -> On Created : System -> Spawn Object -> HealthBar (Position: Enemy.X, Enemy.Y-50), then another action -> Enemy -> Set instance variable "id" to idTracker. Then another action -> Add +1 to idTracker (This makes sure every enemy has a unique ID). Then another action -> HealthBar -> Pin to Object -> Enemy. Then another action -> HealthBar -> Set "id" to Enemy.id

    Then on a new event:

    If HealthBar.id = Enemy.id (this should work iirc) : HealthBar -> Set Width -> (Enemy.hp / Enemy.maxHP) * 100 (or replace 100 with whatever width the HealthBar is when full)

    ____________________

    Sorry if this is long or confusing. If you want me to recreate what I just typed above and send you the file, let me know.

    Edit: Fixed a typo

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)