Jump to content

Get trapledges to fall in y direction only


Zuflus
 Share

Recommended Posts

I thought this would be a simple fix, but so far can't figure it out at all. I have something I call trapledges that is going to fall in the y direction when colliding with player. However, I can not get them to stop moving in the x direction if the player touch the side of them. In my code I have a commented out if test in the update function. I've tried it out both there and in the else if test where the trapledges get made. also tried out different things in the test as changing velocity.x = 0; to for example gravity = 0; or trapLedge.immovable.x = true; and so on. Still won't stop floating to the side if the player touch the sides of the ledge, instead of landing ontop of it.

Added two jpgs of the game, with an arrow showing how the ledge move. A cross to show which way I want the ledge to stop move.

 

var playState = {

    create: function() {

for (i = 0; i < 100; i++) {
            var trapRandomizer = (Math.random() * 0.6) + 0.3;

            var randomYPos = (Math.random() * 200) + 290;
            var randomXSize = (Math.random() * 0.6) + 0.3;
            var randomYSize =(Math.random() * 0.8) + 0.6;

            //console.log("x: " + randomXSize + "Ran" + trapRandomizer)

            if (trapRandomizer > 0.4) {
                var ledge = platforms.create(ledgeXPos, randomYPos, "ground");
                ledge.scale.setTo(randomXSize, randomYSize);
                ledge.body.immovable = true;

            }
            else if (trapRandomizer <= 0.4) {
                console.log("Trapledge");
                var trapLedge = trapPlatforms.create(ledgeXPos, randomYPos, "ground");
                trapLedge.scale.setTo(randomXSize, randomYSize);
                trapLedge.body.immovable = false;    
            }

   

}

update: function() {

/*
        if (game.physics.arcade.collide(trapPlatforms, player)) {
            trapPlatforms.body.velocity.x = 0;
            trapPlatforms.body.velocity.y = 300;
        }*/

},

downwards.jpg.a9c6c32bd8ef2f49c7a2e596bdc973a2.jpgSideways.jpg.bff2fa3ae47a281f81829fd26cc7ce9d.jpg

Link to comment
Share on other sites

So far no difference, can't seem to figure out how you use the overlap thing also. May be because it's the middle of the night, so I should see if I can find a proper example or tutorial about it that I understand tomorrow.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...