Recommendations for syncing Sprite and Hitbox objects

Not favoritedFavorited Favorited 0 favourites
  • 2 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • In my game I have hitboxes and sprites as separate objects. This *was* working fine for a while but recently had an issue with multiple of the sprite objects be affected by one hitbox object. For example if I have something called enemy1 (note that all of these enemies are in a larger Family called Enemies,) if I change its animation after being damaged then some of (not all of them only some) will change to have that animation. I've been passing their (the sprites) UID through a variable assigned to each hitbox. Though I'm not sure if I'm doing it correctly or even if this is the correct way to go about doing things. (See screenshot for more info.)

    My second question would be.. Is it even worth it to separate Hitboxes and sprites for enemies? Like for a player object it makes sense but for something that has more than one instance is it just better to have one enemy object that contains both animations and hitboxes?

    Also I'm willing to share a c3p file later if needed.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I suspect the problem is caused by picking by UID. If the event runs for multiple enemy instances, the "Pick instance with UID" condition won't work correctly. You could try fixing it by adding "For each Enemies" as the first condition.

    That said, linking objects by UID is an outdated approach. I'd recommend connecting sprites and hitboxes using hierarchies instead. You can do this in the event where an enemy is spawned, or even create the hierarchies manually in the editor (on an unused layout) and spawn the entire hierarchy.

    For example, creating a ZombieHitbox with the "Create hierarchy" checkbox enabled will automatically create both the hitbox and the sprite with zombie animations.

    Then, in events you can simply use the "Enemies Pick child EnemySprites" condition.

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