Bullet collision with instance of a family object [SOLVED]

0 favourites
  • 3 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • Hello there!

    I am becoming desperate about a problem, I have with bullet collisions on instances of family objects. First of all, here is a screenshot of my creation in action:

    Nothing special, as you can see: A Top-Down-Shooter.

    The world is randomly created. At time, I have created two families for the creation of the foliage:

    fam_foliage_trees

    fam_foliage_rocks

    Inside are different sprites. Each sprite shall have different properties. In my particular problem: I want to assign random health-points variables to each instance, via giving the whole family an instance variable:

    family instance  varibale name: hp
    value: random(5, 10)[/code:3vc5p7fp]
    
    When the health-points drop to zero, the object instance, I was aming on, shall be destroyed.
    In my main event sheet, I included the following "lines of code":
    
    [code:3vc5p7fp]on created -> fam_foliage_rocks -> set value -> fam_foliage_rocks.hp -> random(5, 10)
    spr_bullet -> on collision with fam_foliage_rocks -> subtract from fam_foliage_rocks.hp -1
    system -> every tick -> compare value -> fam_foliage_rocks.hp "less or equal" 0 -> destroy[/code:3vc5p7fp]
    
    Problematic results:
    [ul]
    	[li]Every instance of fam_foliage_rocks objects now have the same randomly assigned health-points.[/li]
    	[li]If they drop, all instances of the objects, belonging to fam_foliage_rocks will be destroyed.[/li]
    [/ul]
    The game will be filled with a lot of more objects / families and stuff to interact with. Because the stuff should mainly be randomly generated, I will be encountering this problem very often. I searched the tutorials, forums and a lot of external results, but still haven't found a proper solution.
    
    Questions:
    [ul]
    	[li]How can I assign random variables for every instance of family objects?[/li]
    	[li]How can I affect (destroy) only a specific instance of family objects?[/li]
    [/ul]
    I hope you can help me out.
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Based on this logic you shouldn't really be encountering these issues.

    On created set hp will set hp only for the instance that was just created.

    The on hp less than or equal 0 check should only pick individual instances.

    Can you post a screenshot of the events because everything seems right here.

  • Thanks for your reply.

    In the meantime I was able to solve the issue. It worked out, like you said. There was no problem with the collision detection of family instances. I have overseen a mistake I made in some earlier conditions. Here is my event-sheet:

    Don't be irritated, I have balanced out some values. As you can see in the section player_weapon_behaviour / Collision effects , there are some disabled lines of "code" which caused a conflict. They were there for the creation of a spark-effect, that appeared when a bullet was hitting an object. All objects that should cause this spark-effect, were put into the family fam_colliders_bullets, which also included the terrain objects. This must have caused the conflict. When this condition is disabled, everything works as it should.

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