Sign in to follow this  
edmundg86

Physics engines - which one do you pick?

Recommended Posts

I am about to start work on a top down game which sees the player moving around the screen with a view from above.

 

So far in previous games I have only used the arcade physics and looked at platform style games.

 

I am a complete newbie and am now venturing out of tutorial land.

 

I have little knowledge of any of the physics engines (including arcade).

 

I only need basic physics for movement and collision.

 

If I create the player using arcade physics when they start to move it treats it like a front on view so the player drops (simulated gravity).

I need to just allow the player to move freely from a top-down view (see attached image for rough idea).

 

Please can anyone help suggest the best way forwards?

 

Thanks

post-14982-0-85408700-1435147424.png

Share this post


Link to post
Share on other sites

I don't fully understand your problem. But I guess you have implemented the getting started guide of phaser.io (which has gravity pulling the player down to the bottom of the screen until it hits the ground) and want to start implementing your game form this point.

 

In this case you simply can implement it this way:

update: function () {    if (cursors.left.isDown)    {        player.angle -= 4;    }    else if (cursors.right.isDown)    {        player.angle += 4;    }    if (cursors.up.isDown)    {        //  The speed we'll travel at        currentSpeed = 300;    }    else    {        if (currentSpeed > 0)        {            currentSpeed -= 4;        }    }    if (currentSpeed > 0)    {        game.physics.arcade.velocityFromRotation(player.rotation, currentSpeed, player.body.velocity);    }}

You should initialize the currentSpeed variable at the top of your game.js

var currentSpeed = 0;

Does this help you?

 

P.S.: I'm often "stealing" code snippets from the Tanks example on phaser.io. In fact the code snippet above is taken from this example.

Share this post


Link to post
Share on other sites

Sorry I should have put an example in of the actual game to help.

 

The starting point is here: http://eg-family.zz.mu/games/shopdash/game.html

 

I have now not added the player to the physics engine and have just hooked up the cursor keys.

 

From the example I am setting the players velocity but once I hit one of the arrow keys they it just continues in the same direct till it hits the bounds.

 

Thanks for your help, I've only just started on the forum too and so far along with the example it has all been very helpful!

Share this post


Link to post
Share on other sites

Hello,

 

if the gravity was giving you troubles in the first post, then just set it to zero (for example gravity in y axis this.player.body.gravity.y = 0).

 

For movement adjust the code from tmuecksch and go with:

create: function () {  this.cursor = this.input.keyboard.createCursorKeys();  this.input.keyboard.addKeyCapture([Phaser.Keyboard.UP, Phaser.Keyboard.DOWN,                                     Phaser.Keyboard.LEFT, Phaser.Keyboard.RIGHT]);},update: function() {  if (cursor.left.isDown) {    this.player.body.velocity.x = -50;  // some value  }  if (cursor.right.isDown) {    this.player.body.velocity.x = 50; // some value  }  if (cursor.up.isDown) {    this.player.body.velocity.y = -50; // some value  }  if (cursor.down.isDown) {    this.player.body.velocity.y = 50; // some value  }  else {    this.player.body.velocity.x = 0;  // this stops the player in x direction (velocity-wise)    this.player.body.velocity.y = 0;  // this stops the player in y direction (velocity-wise)  }}

Don't forget the else part, where you set player's velocities to zero (so he stops moving), and place this code into your update function as I suggested above.

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...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.