Jump to content

[Phaser Tanks] - How to move... Backwards ?


Mikoziq
 Share

Recommended Posts

Hello Everyone,

 

So... how should I refactor the code to gain my tank ability to move reverse ?

 

Should i use else if statement in those lines ?

if (cursors.left.isDown)    {        tank.angle -= 4;    }    else if (cursors.right.isDown)    {        tank.angle += 4;    }    if (cursors.up.isDown)    {        //  The speed we'll travel at        currentSpeed = 300;    }   if (cursors.down.isDown) ???    {         //something   }    else    {        if (currentSpeed > 0)        {            currentSpeed -= 4;        }    }
Link to comment
Share on other sites

  • 6 months later...

I'm having the same issue. I already tried what Snade and Skeptron suggested:

if (cursors.up.isDown){	//  The speed we'll travel at        currentSpeed = 300;}
else if (cursors.down.isDown){ 	//  The speed we'll travel at        currentSpeed = -300;}

Pressing the down arrow still does nothing. Seems simple enough, but I'm new to phaser. What am I missing here? Does it have to do with this?

if (currentSpeed > 0)
    {
        game.physics.arcade.velocityFromRotation(tank.rotation, currentSpeed, tank.body.velocity);
    }

 

Link to comment
Share on other sites

  • 3 weeks later...

            if (cursors.up.isDown) {
                if (currentSpeed >= 300) {
                    currentSpeed = 300;
                } else {
                    currentSpeed += 20;
                }
            } else if (cursors.down.isDown) {
                if (currentSpeed <= -300) {
                    currentSpeed = -300;
                } else {
                    currentSpeed -= 20;
                }
            } else {
                if (currentSpeed > 10) {
                    currentSpeed -= 10;
                } else if (currentSpeed < -10) {
                    currentSpeed += 10;
                } else {
                    currentSpeed = 0;
                }
            }

            game.physics.arcade.velocityFromRotation(tank.rotation, currentSpeed, tank.body.velocity);

--------------------------

This worked for me.

Link to comment
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...
 Share

  • Recently Browsing   0 members

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