Search the Community
Showing results for tags 'player movement'.
-
I'm playing around with an infinite scroller game idea (think Temple Run) on the basis that the player stands still, and the terrain moves towards the camera, giving the illusion of forward motion. I added some simple random box meshes on top of the path that the user needs to navigate around (game over otherwise), and some gaps in the ground that the player can fall thru (game over). Since i need collision detection and basic player gravity I set up using CannonJS. That seems to work OK: the player would fall through the gaps, but for some reason the hit detection for the obstacles would bug out, sometimes letting the player mesh go halfway thru (imposter out of sync with mesh). For the motion of the path blocks i simply did mesh.position.z -= .1 in each render loop. After reading some more on this it seems like manipulating physics objects like this is not a good idea (should use impulse/force instead)? Funny thing is, if I turned down the speed to a crawl the imposter worked as it should and seemed to match up with the mesh. If I can't use this approach to moving the ground, what would be a better solution? I also thought about setting a linear velocity in the ground, but since its mass is set to 0 this has no effect. I think my main question is this: How can I implement a simple gravity + jump functionality manually (colliding with a flat predicable/same height ground)?
- 14 replies
-
- infinite scroller
- player movement
-
(and 1 more)
Tagged with:
-
Currently, I have this script in my application to move the player in a circle using the mouse (taken from this example: http://phaser.io/sandbox/CpErwgAd/play) : var mouseX = this.input.x; var mouseY = this.input.y; theta = Math.atan2(mouseX-cX, mouseY-cY) var newX = Math.sin(theta) * radius; var newY = Math.cos(theta) * radius; rocket.x=cX + newX; rocket.y=cY + newY;I would like to change the above to key control ("A"/'D") -- but can't get the right code to work. FYI, I am using the cursor arrows for other movement with no problem. Any assistance would be greatly appreciated.
-
I am building a game using a Tile Map. The Map loads and all appears fine. I can move the player right and left with no issues. Unfortunately, I have been unable to get movement up and down. I have scoured web with no success. I am not looking for 'Pac Man" auto movement. I want the player to move on keyboard input. Here is the relevant sections of code: this.physics.arcade.gravity.y = 200; // The player and its settings player = this.add.sprite(200, this.world.height - 250, 'dave'); // We need to enable physics on the player this.physics.arcade.enable(player); // Player physics properties. player.body.bounce.y = 0.2; player.body.gravity.y = 300; player.body.collideWorldBounds = true; // Our animations of walking player.animations.add('left', [0, 1, 2, 3], 10, true); player.animations.add('right', [5, 6, 7, 8], 10, true); player.animations.add('up', [0, 1, 2, 3], 10, true); player.animations.add('down', [5, 6, 7, 8], 10, true); // Keyboard Controls cursors = this.input.keyboard.createCursorKeys();// Reset the players velocity (movement) player.body.velocity.x = 0; if (cursors.left.isDown) { // Move to the left player.body.velocity.x = -150; player.animations.play('left'); } else if (cursors.right.isDown) { // Move to the right player.body.velocity.x = 150; player.animations.play('right'); } else if (cursors.up.isDown) { // Move to the Up player.body.velocity.y = 150; player.animations.play('up'); } else if (cursors.down.isDown) { // Move to the Down player.body.velocity.y = 150; player.animations.play('down'); }Any guidance would be greatly appreciated.
- 3 replies
-
- phaser
- player movement
-
(and 2 more)
Tagged with: