Jump to content

Velocity not working for Ninja Physics


xergon
 Share

Recommended Posts

Hi,

Programming on my game, i came across a very strage behavoir.
For some reason my body does not react to velocity. It can be set, but it does not have any effect. MoveLeft or MoveRight on the other hand works fine.

Is this a commen bug, or am i just missing something?
Help would be greatly appreciated.

 

Here is some of the code I use:

var player;var ground;var map;var levelLayer;var objectsLayer;var bg;var spikes;var collision_tiles;var move_distance = 50;var jump_height = 10000;var playState = {  create: function() {    // cursor    cursors = game.input.keyboard.createCursorKeys();    // Create Background and fix camera on background    bg = game.add.sprite(0, 0, 'background');    bg.fixedToCamera = true;    // Create map from tileset and JSON & add Collision & add .png's    map = game.add.tilemap('test2');    map.addTilesetImage('tiles_spritesheet','tiles');    map.addTilesetImage('magicBoni','magicBoni');    map.addTilesetImage('Map','Map');    map.addTilesetImage('spike-up','spike-up');    map.addTilesetImage('black-tiles64','black-tiles64');    // Add layers to map    levelLayer = map.createLayer('Kachelebene 1');    levelLayer.resizeWorld();    map.setCollisionBetween(1,3000,true,levelLayer);    // Create slope map    var slopeMap = {'1':1,'2':1,'3':2,'4':3,'5':4,'6':5,'7':6,'8':7,'9':8,'10':9,'11':10,'12':11,'13':12,'14':13,'15':14,'16':15,'17':16,'18':17,'19':18,'20':19,'21':20,'22':21,'23':22,'24':23,'25':24,'26':25,'27':26,'28':27,'29':28,'30':29,'31':30,'32':31,'33':32};    collision_tiles = game.physics.ninja.convertTilemap(map,levelLayer,slopeMap);    //  Player settings    player = game.add.sprite(0, 20, 'player');    game.physics.ninja.enableCircle(player,player.width/2);    game.physics.ninja.enableBody(player);    game.physics.ninja.enable(player);    player.body.bounce.y = 0.8;    game.physics.ninja.gravity = 0.3;    game.camera.follow(player);    game.add.sprite(0, 0, 'foreground');  },  update: function() {      for (var i = 0; i < collision_tiles.length; i++) {            player.body.circle.collideCircleVsTile(collision_tiles[i].tile);      }      if (cursors.left.isDown) {        player.body.moveLeft(move_distance);      } else if (cursors.right.isDown){        player.body.moveRight(move_distance);      }      // DOES NOT WORK!      if (cursors.up.isDown && player.body.touching.down == true) {        player.body.velocity.y = jump_height;      }  }}
Link to comment
Share on other sites

  • 1 month later...

 

      // DOES NOT WORK!      if (cursors.up.isDown && player.body.touching.down == true) {        player.body.velocity.y = jump_height;      }

 

replace : player.body.velocity.y = jump_height;

by : player.body.moveUp(jump);

where jump is a number

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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