(Solved) Collision Errors, Is this a bug? Please Help

KGBlag

  • Posts: 38
I'm having trouble with figuring out what exactly I'm doing wrong. Ok, I create an enemy that is killed by jumping on the head, it works as intended until start having it move, now it doesn't seem to respond at all. I bounce off it's head and my player responds as intended, bouncing up but the enemy doesn't die. I've written a simplified version of the code as an example for you all that is similarly flawed. It works if it's set not to move but doesn't otherwise. Please help, thanks.

Update: Ignore the previous statements. I run a few tests and I don't believe it's the problem with the code and I not sure if it's actually a bug. I've made a playable demonstration of the problem: http://www.stencyl.com/game/play/39680


« Last Edit: November 26, 2018, 04:36:54 am by KGBlag »

Madolah

  • Posts: 3
In the first segment,  change to:

If << The top of [SELF] was hit>> and [Not 'DEAD']
this will always detect Self for hit and not specific actor. So each time you jump on a new instance of actor it kills ITSELF and not other versions of that actor instance.



KGBlag

  • Posts: 38
That's not really the problem. The code works fine when the enemy isn't moving, I jump on it and it dies. If I have it in motion it becomes unresponsive.

KGBlag

  • Posts: 38
Perhaps I've been explaining things a bit confusingly. I've programed an enemy that dies when it is stomped on. While it works as intended when coded to stay still (speed=0) if I set it to even move even a bit then the collision detection stops working. I can't seem to figure out why it's doing this. If anyone has any information please help. I apologize for prodding and will cease from this point on.

JeffreyDriver

  • Posts: 2262
I can't see an obvious reason for it. Though in your updating event, you don't need the 'Dead = false' bit. You can just stick the x-speed block directly in the updating event as the actor is only killed when dead equals true.

A guess would be that maybe you're colliding with the side of an actor rather than the top of it. Perhaps you could try using distances to calculate the collision?

Stick in some blocks to detect collisions from the left and right and use print blocks to write to teh log viewer so you can see what's going on.

KGBlag

  • Posts: 38
I've ran a few tests. I've found that if the enemy is moving up it can be killed. Could this have something to do with the hitboxes themselves? I have them both set as solid, although iv'e also tried to set the enemy as a sensor but now the player just ends up passing through the enemy when set to detect top collisions. It does however detect any random collision when set to kill upon detecting the player.   

KGBlag

  • Posts: 38
I've made a playable demonstration of the problem: http://www.stencyl.com/game/play/39680

merrak

  • *
  • Posts: 2738
I'd have to see the code and the collision shapes to have a better sense of what's going on, but it's worth noting that sometimes the 'hit from (direction)' blocks can be finnicky. Usually what I do is just check for a collision--not from any particular direction--and then check the y coordinates of the two actors.

For stomping, you can check if ((y of the player) - (some percentage of the height of the player)) is greater than (y of the enemy).

With this approach, you'll have to play with the percentage so that a collision from the side doesn't count as a stomp.

Another alternative to using y coordinates would be to compute the angle from the enemy to the player. If the angle is in the range of 270 +/- (some amount) then the player is landing from on top. If you use this approach, start with +/- 45 and see if that works. There's an easy math extension you can use to get some more math blocks to do the calculation. Just be sure to compute the angle from the centers of the actors (x,y of self + half width,half height of self).

KGBlag

  • Posts: 38
Thanks a lot for the help! I still couldn't get it working with them both being solid and only once I made the enemy a sensor to the player did it start responding. I implemented the first suggestion and it is working although it only seems to work if I give it a space to overlap a bit. The hitboxes are 20x20 cubes enveloping the entire sprite. I don't know if it must overlap or not in order to get a collision. 

Edit: Ok, using what you told me I've created a collision detector that CANNOT IN ANYWAY neglect a stomp. It's rough and there are still loopholes like getting it to only work on the top but I think it's on its way. I posted it below the first code. I think the default collision blocks can use some work. Thanks again for all of the help!  :) 

« Last Edit: November 25, 2018, 10:56:09 pm by KGBlag »