Tom Atom

[Phaser] Brick Stacker

Recommended Posts

@NumbOfAthma - problem of physics engines is in how they work. If you have two bricks - one on top of other, then gravity sinks upper brick into bottom one. Physics engin then solves this penetration and repels birck from each other to restore position befeore they started to penetrate. But it can happen, that another new penetrations may appear (with floor, other bricks on side, ...) For this physics engines usually have several iterations for solving positions per frame.
 Problem is, that with pile of bricks you have really lot of interactions betwwen them. With 5-6 bricks, that should stay still, usuall number of iterations per frame is not enough. Bricks start to strangely slide on top of each other and so on. When bricks are falling and should bounce from each other, then everything is OK, but not when it should be static and stable... so I had to come with another solution...

 Fortunatelly, I drink a lot of tea! It has no impact on my skills, but I have lot of empty boxes, that look like brick :) Simply, when will such brick fall off your table? When more than half of it is over edge. If brick above is too much left over edge or too much right (see first row on picture) it will fall. Then I used boxes do simulate more complex situations and I found, that for game it would be enough to take brick N and: take all bricks above current brick and sum their parts to the left and to the right from edge of brick N. See second row. On series of pictures on right you can see increasing tower one by on. In step 1 and 2 brick is still OK, because more of the mass is still above bottom brick. When 3rd brick is dropped, mass on right is higher then on left and all three bricks will fall. I do this check for every brick in pile - always suming all bricks above it as described, because point of break can be at different places.


 This is fake physics, but it looks good. When I find point of instability, I rotate upper part of tower around it by 5-10 degrees and then I switch bricks that should fall into P2 objects to just let them fall nicely. Because it is already rotated and gravity continues fall immediatelly, it does not suffer from looking like elastic soft bodies (which would if it was not rotated ... because of interactions - iterations problem above).

 Next thing: only visible part of tower is calculated - it would be unfair to break it two or three screens below display when player can not see it. Tower below screen is just recorded - no actual bricks are there. When game ends and camera scrolls down, sprites for bricks are placed at correct positions according to recorded data.

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.