You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The documentation for the hit function (http://craftyjs.com/api/Collision.html#-hit) provides an example, which I have found may lead to the game entering an infinite recursion if two events are triggered at the same time.
This relies on the last know OK position, instead of the event position which may also be in collision with 'wall'. I suggest updating the official documentation so that people don't get stuck with this bug.
For information I am working with Firefox
The text was updated successfully, but these errors were encountered:
if(hitData.type==='SAT'){// SAT, advanced collision resolution// move player back by amount of overlapthis.x-=hitData.overlap*hitData.nx;this.y-=hitData.overlap*hitData.ny;}
Where backing out the entity by just the amount necessary to end the first collision can cause a second collision?
No I haven't tried the hitData of type SAT. I have only tried MBR. The issue is with this code:
{// MBR, simple collision resolution// move player to previous positionthis.x=evt._x;this.y=evt._y;}
From what I understand, I got the error when I was pressing both key 'arrow down' and 'arrow left' at the same time, while my entity was just above another item of type wall.
This triggered twice the 'Move' event, one for the key down - which would place the entity one down inside the wall in x0, y0+1, and then one for the key left which would position the entity to x0-1, y0+1. When Crafty would handle the second event, it would position back the entity to x0, y0+1, which is still within the wall; hence the infinite loop. I hope it's clear!
The code which causes the infinite loop is this one:
The documentation for the hit function (http://craftyjs.com/api/Collision.html#-hit) provides an example, which I have found may lead to the game entering an infinite recursion if two events are triggered at the same time.
Here is a fix (on a simplified example):
This relies on the last know OK position, instead of the event position which may also be in collision with 'wall'. I suggest updating the official documentation so that people don't get stuck with this bug.
For information I am working with Firefox
The text was updated successfully, but these errors were encountered: