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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.