anthkris

Player collide with floor sides?

Recommended Posts

Howdy all,

I've looked everywhere but I can't seem to find an answer. I'm making an infinite scroller. The platforms are automatically generated and they are made up of a pool of floor sprites nested into a pool of platforms (groups of floor sprites). For example:

// Creating platforms in Game.js

createPlatform: function(){
    var nextPlatformData = this.generateRandomPlatform();
    
     if (nextPlatformData) {
       this.currentPlatform = this.platformPool.getFirstDead();
       if (!this.currentPlatform) {
         this.currentPlatform = new SupRun.Platform(
this.game, this.floorPool, nextPlatformData.numTiles,this.game.world.width + nextPlatformData.separation, 
nextPlatformData.y, -this.levelSpeed, this.coinsPool, this.enemiesPool, this.enemySprite, 
this.player, false);
       } else {
         this.currentPlatform.prepare(
nextPlatformData.numTiles, this.game.world.width + nextPlatformData.separation, 
nextPlatformData.y, -this.levelSpeed, this.coinsPool, this.enemiesPool, this.enemySprite, 
this.player, false);
       }
       
       this.platformPool.add(this.currentPlatform);
       this.currIndex++;
     }
  }

//Creating groups of floor sprites in Platform.js prefab

SupRun.Platform.prototype.prepare = function(numTiles, x, y, speed, player) {
  //console.log(speed);
  this.alive = true;
  
  var i = 0;
  while(i < numTiles){
    
    var floorTile = this.floorPool.getFirstExists(false);
    if (!floorTile){
      floorTile = new Phaser.Sprite(this.game, x + i * this.tileSize, y, 'floor');
    } else {
      floorTile.reset(x + i * this.tileSize, y);
    }
    this.add(floorTile);
    
    i++;
  }
  //set physics properties
  this.setAll('body.immovable', true);
  this.setAll('body.allowGravity', false);
  this.setAll('body.velocity.x', speed);
  
  this.addCoins(speed);
  this.addEnemies(speed, this.player);
  
};

 

The player collides with the top of the of the platforms just fine. However, I would like the player to hit the side of the wall and just fall straight down, instead of falling through.

Screen Shot 2017-01-23 at 12.16.35 AM.png

Is this possible?

Share this post


Link to post
Share on other sites

I finally figured this out thanks to this thread: 

I was manipulating player.x, which was fiddling with collision. Now I just need to fix an issue where the player's position keeps getting screwed up when hitting an enemy.

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.

Guest
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.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.