#Sokoban ice physics - Detection of Crate after it has moved.

11 messages · Page 1 of 1 (latest)

full phoenix
#

I am making a Sokban game with ice physics, however I am getting stuck on this edge case whenever i push an crate while it is on ice, it moves to the correct spot but my character only moves one space.
the player and the crate uses the same script because i wanted to use modular components.

after some debugging I found that it is detecting a collision with the crate as if it is on the middle ice tile.
pic 1 - normal before moving
pic 2 - normal after moving
pic 3 - edge case before moving
pic 4 - edge case after moving
pic 5 - when player is detecting the crate after it has moved
pic 6 - debug menu at pic 5
other pics will be the code for the movement.

bonus question: if you have any tips to improve my code in other ways, I would be thankful for the knowledge.

stone trout
#

i have potentially a very unpleasant answer to your "tips to improve code" question, which is to keep track of the state of the game in some kind of array or something and, instead of using collision detection and things to handle movement and the rules of the game, just compute where everything should go whenever you move, update the array, and then draw the result.

(disclaimer: i have done some projects that are similar you're doing here, and also similar to what i describe above, and they both work! i have found i now prefer the latter)

#

as for your original question, though, could you include a pic of what you want the final state from the edge case push to be?

full phoenix
#

the same as pic 2

#

but for the block im pushing for in pic 3 and 4

stone trout
#

so pic4 seems to show the raycast pointing multiple tiles ahead of the player. could you normalize the raycast's target position to make sure it only points one tile ahead?

#

maybe something like this: ray_cast.target_position = (same code you had as before).normalized() in line 40

#

(also, any reason direction is not a Vector2i? seems like it would make lines 30-33 as simple as target_tile = current_tile + direction and in lines 57, 85, 95 you wouldn't have to put direction inside Vector2i())

full phoenix
#

thanks for the tips. i solved the issue i had. btw is there a good tutorial for the array thing for future refrence. thanks in advance.

twin moss
#

it's actually using a dictionary rather than an array. if you have any questions about it let me know. tried to keep it as simple as possible and added comments above all critical lines