How to stop when colliding with a box?

Triangularity GamesTriangularity Games Founder/OwnerMarylandMember Posts: 140

I'm making an infinite platformer, where the player needs to stop when he collides with a box obstacle. The only thing that moves in the game is the ground under the player (the player.position.X is constrained). This means that I drop the box on the ground and the ground moves it toward the player like a conveyor belt. I am trying to make it so the box moves with the ground, but cannot be moved by the player AT ALL. The player can jump on top of the box or over the box (meaning he needs to be able to move on top of the box). This proves difficult when trying to use the collision behavior because the player gets stuck on top of the box and can only move when he jumps (move in the air). I have tried several approaches to this problem and none of them are accomplishing this the proper way. Any solutions? Is there a way to do this with physics? Like make the box so strong that the player cant move it no matter what, but can still jump on top of it and move on it...Any help/advice would be greatly appreciated. Thanks in advance!

Best Answers

  • IceboxIcebox Posts: 1,485
    Accepted Answer

    @Triangularity Games said:
    The player can move left and right (arrow keys) and can jump (up arrow key). When he encounters the brown box

    What twayne is saying is true . The player in your demo is not moving left or right , your moving the ground left and right , thats why your facing alot of complications , you need to set your logic in the opposite way.

    If the player collides with the box from the sides , don't allow the player to move the ground left or right (simulating a character movement) , if the player is above the box allow the ground to move left and right and so on, but you will have to work on the logic you will face many bugs , it will also include playing around with the friction a bit cause of the way your moving the box on the ground.

  • ValanValan Posts: 410
    edited August 2017 Accepted Answer

    Is this what you want?

    The main issue is to make the movement negative to the collision. So setup a When collision occurs do (nothing) Otherwise movement happens.

    Also, generally, any collision actors shouldn't be Can Sleep but need Better Collisions.

    Changed the layer order of the actors so the player at the front.
    Changed the Density of the player since any movement depends on lack of collision.

    Hope this helps.

Answers

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited August 2017

    Disclaimer: platformers are not at all my strong suit

    Here's how I'd start out... (up arrow key repeatedly to jump)

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • Triangularity GamesTriangularity Games Founder/Owner MarylandMember Posts: 140

    @tatiang said:
    Disclaimer: platformers are not at all my strong suit

    Here's how I'd start out... (up arrow key repeatedly to jump)

    Kinda, but not quite. In your example, the scene moves automatically. See if you can figure out with my movement...its very weird and peculiar I've played around with the physics, and I can't seem to find a workaround.

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    @Triangularity Games said:
    In your example, the scene moves automatically.

    Okay, I see in your project file how you've set this up. Makes sense. I don't have a fix though, sorry!

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922

    Use friction. Friction needs high numbers, both the ground and box need to have an amount set or friction will not work. Also make sure your player actor has zero friction. Also make sure bounce is set to zero.

  • Twayne2Twayne2 Member Posts: 458

    real simple, just make the box have tone of density, (say, 5k.)

  • Triangularity GamesTriangularity Games Founder/Owner MarylandMember Posts: 140

    @The_Gamesalad_Guru
    @Twayne2

    Did you see if this worked with the test file in this thread? I've tried playing with the physics in all sorts of ways and never found a solution...let me know if either of you can. Thanks!

  • Twayne2Twayne2 Member Posts: 458

    Um the file doesn't work for me... I extracted it but the gsproj doesn't have anything, as it is just blank.

  • Twayne2Twayne2 Member Posts: 458

    wait scratch that.

  • Twayne2Twayne2 Member Posts: 458
    edited August 2017

    Ok I need to know what you want the box to do when it collides with the player... does it push him back? Is there a zone behind the player that destroys him? If so then I believe I have a solution. :smile:

  • Twayne2Twayne2 Member Posts: 458

    Well I guess that you don't want the solution very much lol....

  • Triangularity GamesTriangularity Games Founder/Owner MarylandMember Posts: 140

    Sorry @Twayne2 , been away for a few days. The player is supposed to completely stop when he hits the brown obstacle (as if it were a big box). However, he should be able to jump over it in both directions (unless the stopper on one of the ground blocks the player from jumping backwards; left).

  • Twayne2Twayne2 Member Posts: 458

    What do you mean by completely stops? The player was never moving...

  • Twayne2Twayne2 Member Posts: 458

    ?

  • Triangularity GamesTriangularity Games Founder/Owner MarylandMember Posts: 140

    @Twayne2

    The player can move left and right (arrow keys) and can jump (up arrow key). When he encounters the brown box, he should stop when he hits it (the same way we would stop if we hit a large heavy box. However, he can jump and move on top of the box or over the box. This should work in both directions.

  • Twayne2Twayne2 Member Posts: 458
    edited August 2017

    I would suggest adding a new attribute rule to your movement rules saying:
    (if game attribute (tracker) is 0,)
    if key press right is down:
    move.

    When the obstacle and player collide, change game attribute (tracker) to 1. Thus the ''player'' can't move, (but he can still jump.) Then figure out a way to change the game attribute (tracker) back to 0 once the player has jumped over the obstacle. Hope this helps! :smile:

  • BBEnkBBEnk Member Posts: 1,764
    edited August 2017

    @Triangularity Games

    just move the player and camera then loop the scene for endless play.

    keep in mind order of operation is very important doing it this way otherwise you will get a flicker on reset, I build all my endless games like this works very well once you get the hang of it.

    heres a example might have a glitch but works you can figure out the rest.

Sign In or Register to comment.