Why is my collision behaviour functioning inconsistently (Solved)

SillyGlassBoy

  • Posts: 12
I have a character with a gun, shooting projectiles at monsters. When the projectiles hit the monsters I want the projectiles to be destroyed and the monsters to lose 1 life, being destroyed when their life becomes less than 1. The projectiles are behaving fine but the monsters only behave properly sometimes.

My code for the monsters looks like this.

When created
-set life to [1]

When [self] hits an actor of [bullets] - [first actor][actor of group]
-[decrement] [life] by [1]
-if [life] < [1]
--kill [self]

« Last Edit: October 06, 2018, 02:52:16 pm by SillyGlassBoy »

JeffreyDriver

  • Posts: 1803
What exactly is happening? Are the monsters sometimes losing more than 1 health on each hit? Or are monsters sometimes not dying?
Current Projects:
Retro Redux Compilation (NEW).
Retro Redux (untitled) (NEW).
I always appreciate useful feedback. Thank you.
www.jeffreydriver.co.uk

SillyGlassBoy

  • Posts: 12
They aren't dying, the collision isn't being detected, but it is for the projectile so I don't understand how it isn't for the monster.

JeffreyDriver

  • Posts: 1803
I suspect that the projectiles are sometimes being killed before the monster. So run the code to decrease the monster health before killing the projectile.
Current Projects:
Retro Redux Compilation (NEW).
Retro Redux (untitled) (NEW).
I always appreciate useful feedback. Thank you.
www.jeffreydriver.co.uk

SillyGlassBoy

  • Posts: 12
Yep that fixed it.
I don't understand though. How can only one of them collide with the other?
That's like hitting a tree with an axe and having the bark fall off the tree but the axe passing right through.

JeffreyDriver

  • Posts: 1803
A lot of things depend on frame rate, which is typically 60fps, but it can change depending on performance, so my guess is that sometimes different code was being executed first.
Current Projects:
Retro Redux Compilation (NEW).
Retro Redux (untitled) (NEW).
I always appreciate useful feedback. Thank you.
www.jeffreydriver.co.uk

SillyGlassBoy

  • Posts: 12
Guess it must have been. The actors are moving very quickly so I think that could be part of it.
Thanks for all the help.  ;)