Freezes on collision?

Stencyl Ninja

  • Posts: 246
I think this is the same problem that I am now having in my collaboration :( ...
My code is testing positional collisions for AI, and changing direction of the sprite to obtain a
knocked-down effect. I'm wondering if maybe the direction changes could be the problem.
If so then I guess that I could just turn those into animations, but I doubt I'm lucky
enough for it to be so simple of a solution.

If the Hero is in between the 2 enemies, and one enemy knocks the Hero into the other one
the game crashes and presents a bunch of errors.

I have no idea how to fix this. Everything was just starting to go smoothly too. :(
I had the basics for my AI completed and was starting into the fun stuff.
Does anyone know of a good simple workaround?

coleislazy

  • *
  • Posts: 2607
You're trying to get the x position of a dead actor in the Spear Attack behavior. Check if it is alive first.

ChunkyMonkey

  • Posts: 430
    For anyone experiencing this collsion problem I just use this to keep things unfreezy.
Code: [Select]
{
When this collides with something else
[if <the top was hit>
set y to y of self +1]
[otherwise if <the bottom was hit>
set y to y of self -1]
[otherwise if <the right was hit>
set x to x of self -1]
[otherwise if <the left was hit>
set x to x of self +1]
}

SkullSoft

  • Posts: 1
2 things I find are bound to make the game freeze on a collision event:
1)
 Having the collision box change suddenly. If it enlarges and collides with something, the game will freeze. 2)
 Checking for a collision event in a dead actor. I had this problem, and it really threw me off because it didn't always happen.
>The solution was to recycle the actor instead of kill it. This is rather wasteful of memory, though.

ChunkyMonkey

  • Posts: 430
Thanks, but we already found out what the problem is.

Stencyl Ninja

  • Posts: 246
You're trying to get the x position of a dead actor in the Spear Attack behavior. Check if it is alive first.

I already tried that before and it did not work.

But I did find out what the problem is for sure now.
It's not a Box 2d problem as I had thought that it was.
Instead it is a collisions/direction change bug.
If I take out the direction change code, the game no longer freezes.


    For anyone experiencing this collsion problem I just use this to keep things unfreezy.
Code: [Select]
{
When this collides with something else
[if <the top was hit>
set y to y of self +1]
[otherwise if <the bottom was hit>
set y to y of self -1]
[otherwise if <the right was hit>
set x to x of self -1]
[otherwise if <the left was hit>
set x to x of self +1]
}

Thank you ChunkyMonkey, I'll try adding that in and see if it works or not
so that way maybe I'll still be able to use directional changes.

2 things I find are bound to make the game freeze on a collision event:
1)
 Having the collision box change suddenly. If it enlarges and collides with something, the game will freeze. 2)
 Checking for a collision event in a dead actor. I had this problem, and it really threw me off because it didn't always happen.
>The solution was to recycle the actor instead of kill it. This is rather wasteful of memory, though.

Thank you SkullSoft, although I would like to avoid recycling actors if I can
(partially because I've never recycled them and don't know how to use it)
(and partially because I heard that it uses extra memory and may cause other glitches)
,every possible solution is much appreciated so thanks.


Thanks, but we already found out what the problem is.

I'd rather have more solutions than I can use than just one, as long as it's a working method.
There might be something later on where that information he gave me will come in handy.

« Last Edit: January 26, 2012, 11:16:43 pm by Stencyl Ninja »

ChunkyMonkey

  • Posts: 430
I'd rather have more solutions than I can use than just one, as long as it's a working method.
There might be something later on where that information he gave me will come in handy.
I just got confused thinking he was talking about the collision problem the thread was made for, forgetting he was talking about yours. And btw, my "solution" is just to keep an actor from colliding with 2 things at once getting sandwiched.

coleislazy

  • *
  • Posts: 2607
You're trying to get the x position of a dead actor in the Spear Attack behavior. Check if it is alive first.

I already tried that before and it did not work.

If you look at your error message, it is definitely trying to reference a non-existent actor (the error #1009 part) in the Speark Attack behavior. If you look closely at the message, it throws errors from getX(), moveby() and a TimeTask. I would look for anywhere a dead actor or empty Actor attribute might be passed in to either a "get x of actor" block, a "move by" tween, or inside a "do every x seconds" or "do after x seconds" block. Nothing in that error is related to the physics engine.

Fraz

  • Posts: 159
I've got a similar problem, it's reproducible consistently...

I'm using moving tiles that cannot be pushed by the player(vertical and horizontal, using a variation of the elevator behavior from forge), when he gets sandwiched beneath or beside one of these onto a wall or the floor flash freezes up completely and it must be force closed.

Alexin if you need to see it or if someone has any ideas on how to fix it please let me know
Fraz
     Google Play:
    
   "Platform Panic!"          Platform Panic! Thread

Alexin

  • *
  • Posts: 3132
The fix is quite involved so we are dependent on the original author of the port Box2D port we use. He still hasn't had the chance to do it.

In the meantime, try disabling Continuous Collision if your game permits it.
"Find the fun"
alexin@stencyl.com

Fraz

  • Posts: 159
Alright, for now I'm just designing around the error, not having any moving tiles intersect with floor sections, having a pit below them instead.

Thanks for the update, hope the fix comes soon! :)
Fraz
     Google Play:
    
   "Platform Panic!"          Platform Panic! Thread

ChunkyMonkey

  • Posts: 430
Just curious Alexin, would this problem happen if the actor sandwiching the other into a tileset was a sensor and/or region?

Alexin

  • *
  • Posts: 3132
I can't tell for sure but I suspect it wouldn't happen.
"Find the fun"
alexin@stencyl.com

Stencyl Ninja

  • Posts: 246
Sorry, I should have checked back in on this sooner ... I fixed the problem mine was having.
Yes, mine was not a Box2d problem, dunno why I thought so, it doesn't even mention it in
the errors, <shrugs>  ???  :-[
I couldn't come up with a more elegant solution, so I used what SkullSoft suggested,
to recycle the actor. It worked and is good enough for what I needed.

I currently have an issue regarding animation getting stuck sometimes, but it's so
specific, I'll probably have to get you guys to look at the code. I'll make a new post for it.
Sorry for kinda hi-jacking the thread a bit ChunkyMonkey, course the problem you had
was solved, but guess I shoulda started a new thread to avoid confusion. Sorry bout that.