How to detect a collision once, without killing either actor. [SOLVED]

ConquistadorBob

  • Posts: 21
I have an enemy actor that can be hit with a player bullet. I have it so that if the bullet hits the enemy, the bullet plays a hit animation for .35 seconds, and the enemy actor takes damage once the bullet hits it. The problem is, it keeps taking damage for the whole .35 seconds. Is there a way to make it only take damage once?

I thought of having a game attribute that is like (BulletHitAnimation) which is set to true when it hits an enemy and then false after .35 seconds, when the bullet actor dies.  But this has a few problems that I would like to avoid. It means that the fastest you can hit an enemy is .35 seconds, but you can shoot every .1 seconds.  I would also have to add an If BulletHitAnimation false before every time any enemy gets hit, and that is probably not the best thing to do.  Is there a way around this?

« Last Edit: May 25, 2020, 12:01:09 pm by ConquistadorBob »

corbanwolf

  • Posts: 223
If bullet touches something else:
 If [touched] == false:
  Set [touched] = true,
  Do all the rest of the code.
♪♪♪♪♪♪

ConquistadorBob

  • Posts: 21
Just to clarify, touched would be an attribute attached to the bullet right? Sorry if this question seems dumb, this is the first time I've ever really "coded" anything significant.

corbanwolf

  • Posts: 223
Yes, this whole code should be in bullet actor type
♪♪♪♪♪♪


ConquistadorBob

  • Posts: 21
Yes, this whole code should be in bullet actor type
Ok so I am trying it out and I am not sure this will work for me. The way enemy actors take damage is inside their actor behavior.  When the bullet hits an enemy it just deletes itself, when the enemy hits a bullet it takes its own health down by 1.  How would I make it so that when the bullet hits an enemy, code inside the bullet actor behavior takes that enemy actors health down by 1?

corbanwolf

  • Posts: 223
You can trigger an event in the other actor. Simply inside the bullet code add trigger event in the actor of type. I got no p. A hand so I cannot show you. Basically use block trigger event, put the name of the event and to which actor type.
♪♪♪♪♪♪

ConquistadorBob

  • Posts: 21
You can trigger an event in the other actor. Simply inside the bullet code add trigger event in the actor of type. I got no p. A hand so I cannot show you. Basically use block trigger event, put the name of the event and to which actor type.

What kind of event do I use in that case? Right now the event in the enemy actor is when this actor hits something else.  What kind of event do I change it to such that it only gets triggered when the event is triggered by the bullet event?

Luyren

  • *
  • Posts: 2802
Explanation of what you can use here: https://youtu.be/IsaGtjwo25k
This also has an example of exactly what you are trying to do.
My Stencyl resources are available here: https://luyren.itch.io/
Cutscenes, RPG Elements, Particles, Map System and many more.

corbanwolf

  • Posts: 223
Try something like this.
♪♪♪♪♪♪

ConquistadorBob

  • Posts: 21
Explanation of what you can use here: https://youtu.be/IsaGtjwo25k
This also has an example of exactly what you are trying to do.
Yo thanks. I didn't really understand how they worked at all, and now that I know, they are very useful.