Tank Movement

Hey Guys,

I am playing around with a platform tank game concept. And I am trying to nail down the basic movements before I start. I am having trouble with a few things and I was wondering if you guys could take a look at my test project file. Or offer some assistance.

When you open the file you will be able to move the tank back and forth with the arrow keys of the buttons on the screen. On the right you will see the gun control.

Their are two things I need help with

  1. When the tank goes up the ramp, I would like the tank to follow the ramp better, it need to rotate to the angle. Also I would like to have it so the tank will not slide down once it stops on the ramp.

  2. I would like to add an option to make my tank fly if it hits a certain power up, what will be the best way to handle this.

Thanks in advance

https://www.dropbox.com/sh/95b1j6841gxomh2/AAAJL0OGBDOjV6zGQwFoZZXqa?dl=0

Comments

  • imjustmikeimjustmike Member Posts: 450

    You can easily stop the sliding down by changing the friction in the physics attributes. Whacking it up to 300 did the job, but you should play around to find the best number.

    Change the collision shape to square, then uncheck fixed rotation to solve the angle stuff simply. Play around with custom collision shapes if that is going to be a feature. You'll need to constrain the angle of the turret to the angle of the tank too. You could even do this with an offset so the turret appears to have some spring to it, like modern tanks do.

  • quinn221quinn221 Member Posts: 280

    @imjustmike said:
    You can easily stop the sliding down by changing the friction in the physics attributes. Whacking it up to 300 did the job, but you should play around to find the best number.

    Change the collision shape to square, then uncheck fixed rotation to solve the angle stuff simply. Play around with custom collision shapes if that is going to be a feature. You'll need to constrain the angle of the turret to the angle of the tank too. You could even do this with an offset so the turret appears to have some spring to it, like modern tanks do.

    Thanks! Not sure how to do the offset... do you have an example. Also do you know how I could make it so the take could fly if need be. I am having no luck with it.

  • imjustmikeimjustmike Member Posts: 450

    Don't have any examples to hand - the simple thing is to constrain the turret angle to the tank angle. You could simply delay this with timers and angle thresholds, but there's probably a way to do this with some math and the expression editor - maybe someone like @socks could help you out with that

    By fly, what do you mean? A simple thing would be to add some linear y velocity for a brief moment of time - it would force the tank up, like a jet pack. If your tank has an accelerate behaviour towards the ground it'll come back down when the y velocity 'wears off' - depending on how you build it. If you're a little more specific about the effect you want to achieve we can give more specific help :)

  • quinn221quinn221 Member Posts: 280

    Thanks for the quick reply.

    For the flight option this it was I am trying to accomplish. If my tank hits a power up it will give the take the option to fly. I would like it to fly using an up and down buttons. But if you touch the ground the your flight ability is gone until you hit the up button again. Basically I want the option to make my tank fly like a helocopter .

    I hope this helps

    @imjustmike said:
    Don't have any examples to hand - the simple thing is to constrain the turret angle to the tank angle. You could simply delay this with timers and angle thresholds, but there's probably a way to do this with some math and the expression editor - maybe someone like @socks could help you out with that

    By fly, what do you mean? A simple thing would be to add some linear y velocity for a brief moment of time - it would force the tank up, like a jet pack. If your tank has an accelerate behaviour towards the ground it'll come back down when the y velocity 'wears off' - depending on how you build it. If you're a little more specific about the effect you want to achieve we can give more specific help :)

  • imjustmikeimjustmike Member Posts: 450
    edited March 2017

    That's relatively easy to do.

    Set up your rule to trigger the flight with an attribute. I'd use an integer (rather than a boolean because it gives you more flexibility later on) called game.flight. When you hit the powerup/get enough points or whatever, set game.flight to be 1. In your floor actor have a rule that says when the tank hits it, change game.flight to be 0.

    These rules will allow you to trigger flight and cancel it when the tank hits the floor.

    Create your up and down buttons (assuming you mean on screen buttons, if you mean keyboard keys then change accordingly). In the buttons, have a rule that changes their visibility when game.flight = 1. You could do this with opacity or by moving them onto the screen. You could even use a spawn rule to spawn them, then destroy them when game.flight = 0. How you do it is up to you. But you'll need a global attribute, we'll use another integer and we'll game it game.flight_control. When up is pressed, change game.flight_control to 1, when released, change to 0. When down is pressed game.flight_control to 2, when released, change to 0. (if you do were using opacity rules to show and hide your buttons make sure you add a rule to your touch rule later to ensure they only get touched when opacity is 1 otherwise they'll get touched accidentally)

    These rules will allow you to tell your tank go up and down in the air

    In your tank have a rule that says when game.flight = 0 accelerate towards the ground. This will mean that when your tank isn't flying it's being 'pushed down' on the ground.

    Another rule (or in the else of the previous rule) when flight =1 with some combination of the following:
    something to move the tank up a bit (so it doesn't immediately hit the floor)
    Then, within this rule, create a rule that say when game.flight_control = 1 change liner y velocity to 100 (play around with this number to get the right speed), when game.flight_control =2, change liner y velocity to -100, when game.flight_control = 0 constrain linear y velocity to 0

    Now you have linked the up down controls to your tank.

    And, I think, everything should work.

  • quinn221quinn221 Member Posts: 280

    Thanks so much...works great. Now I just have to nail down my gun. Weed stuff is happening when I flip my graphics

    @imjustmike said:
    That's relatively easy to do.

    Set up your rule to trigger the flight with an attribute. I'd use an integer (rather than a boolean because it gives you more flexibility later on) called game.flight. When you hit the powerup/get enough points or whatever, set game.flight to be 1. In your floor actor have a rule that says when the tank hits it, change game.flight to be 0.

    These rules will allow you to trigger flight and cancel it when the tank hits the floor.

    Create your up and down buttons (assuming you mean on screen buttons, if you mean keyboard keys then change accordingly). In the buttons, have a rule that changes their visibility when game.flight = 1. You could do this with opacity or by moving them onto the screen. You could even use a spawn rule to spawn them, then destroy them when game.flight = 0. How you do it is up to you. But you'll need a global attribute, we'll use another integer and we'll game it game.flight_control. When up is pressed, change game.flight_control to 1, when released, change to 0. When down is pressed game.flight_control to 2, when released, change to 0. (if you do were using opacity rules to show and hide your buttons make sure you add a rule to your touch rule later to ensure they only get touched when opacity is 1 otherwise they'll get touched accidentally)

    These rules will allow you to tell your tank go up and down in the air

    In your tank have a rule that says when game.flight = 0 accelerate towards the ground. This will mean that when your tank isn't flying it's being 'pushed down' on the ground.

    Another rule (or in the else of the previous rule) when flight =1 with some combination of the following:
    something to move the tank up a bit (so it doesn't immediately hit the floor)
    Then, within this rule, create a rule that say when game.flight_control = 1 change liner y velocity to 100 (play around with this number to get the right speed), when game.flight_control =2, change liner y velocity to -100, when game.flight_control = 0 constrain linear y velocity to 0

    Now you have linked the up down controls to your tank.

    And, I think, everything should work.

  • SocksSocks London, UK.Member Posts: 12,822
    edited March 2017

    Constrain turret.x to 50*cos(tank rotation+90)+tank X
    Constrain turret.y to 50*sin(tank rotation+90)+tank Y

    . . . this will put the turret 50 pixels above the tank (90°).

  • quinn221quinn221 Member Posts: 280

    One question on this... I am not sure what you mean by (tank rotation+90)

    @Socks said:
    Constrain turret.x to 50*cos(tank rotation+90)+tank X
    Constrain turret.y to 50*sin(tank rotation+90)+tank Y

    . . . this will put the turret 50 pixels above the tank (90°).

  • SocksSocks London, UK.Member Posts: 12,822
    edited March 2017

    @quinn221 said:

    One question on this... I am not sure what you mean by (tank rotation+90)

    'tank rotation' refers to the rotation/angle of the tank.

  • quinn221quinn221 Member Posts: 280

    I must be doing something wrong... If you have time could you look at my file. I really want to nail down this tank movement before I move on to building the game.

    If you open the project you will see that the tank has a few issues.

    1. the cannon is awkward when moving up the ramps.
    2. The tank flips when I get to the top of the tank.

    I would be grateful for any help

    https://www.dropbox.com/sh/12u23w0e9sngbnh/AACo_htDB274POpBmbkjYEYDa?dl=0

    @Socks said:

    @quinn221 said:

    One question on this... I am not sure what you mean by (tank rotation+90)

    'tank rotation' refers to the rotation/angle of the tank.

  • SocksSocks London, UK.Member Posts: 12,822

    @quinn221 said:
    1. the cannon is awkward when moving up the ramps.

    'the cannon is awkward' could mean anything.

    1. The tank flips when I get to the top of the tank.

    It is catching on the lip of the platform.

  • quinn221quinn221 Member Posts: 280

    Awkward as in the turret cannon does not rotate with the tank when it moves up a ramp

    @Socks said:

    @quinn221 said:
    1. the cannon is awkward when moving up the ramps.

    'the cannon is awkward' could mean anything.

    1. The tank flips when I get to the top of the tank.

    It is catching on the lip of the platform.

  • SocksSocks London, UK.Member Posts: 12,822
    edited March 2017

    @quinn221 said:
    Awkward as in the turret cannon does not rotate with the tank when it moves up a ramp

    You expected someone to get that from 'awkward' !? :) :D

    Constrain turret.x to 50*cos(tank rotation+90)+tank X
    Constrain turret.y to 50*sin(tank rotation+90)+tank Y

    Add this . . .

    Constrain turret rotation to tank rotation

  • quinn221quinn221 Member Posts: 280

    That works...but it added an extra problem. When I fire the gun, sometimes the bullets only fly to the right and don't follow the cannon when it moves....strange

    @Socks said:

    @quinn221 said:
    Awkward as in the turret cannon does not rotate with the tank when it moves up a ramp

    You expected someone to get that from 'awkward' !? :) :D

    Constrain turret.x to 50*cos(tank rotation+90)+tank X
    Constrain turret.y to 50*sin(tank rotation+90)+tank Y

    Add this . . .

    Constrain turret rotation to tank rotation

Sign In or Register to comment.