Bullet collision with instance of a family object [SOLVED]

Get help using Construct 2

Post » Mon Jul 17, 2017 11:05 pm

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:

Image

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:

Code: Select all
family instance  varibale name: hp
value: random(5, 10)


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: Select all
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


Problematic results:
- Every instance of fam_foliage_rocks objects now have the same randomly assigned health-points.
- If they drop, all instances of the objects, belonging to fam_foliage_rocks will be destroyed.

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:
- How can I assign random variables for every instance of family objects?
- How can I affect (destroy) only a specific instance of family objects?

I hope you can help me out. :)
Last edited by robinw326 on Tue Jul 18, 2017 2:13 am, edited 1 time in total.
B
5
S
1
G
1
Posts: 5
Reputation: 835

Post » Tue Jul 18, 2017 12:51 am

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.
B
47
S
18
G
84
Posts: 2,273
Reputation: 49,800

Post » Tue Jul 18, 2017 2:12 am

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:

Image

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.
B
5
S
1
G
1
Posts: 5
Reputation: 835


Return to How do I....?

Who is online

Users browsing this forum: dop2000 and 34 guests