How to make an object defy gravity temporarily?

pxlpfctpxlpfct Member Posts: 37
edited April 2012 in Working with GS (Mac)
Hello! I'm making a game where you shoot magnetic charges from a gun. You have to shoot boxes to make them move. Since I have bullets I'm not using gravity but accelerating down. I'm having problems with the boxes. I need them to have gravity when accelerating down either in the beginning of the scene or when they lose their magnetic charge, but not when they move because to make them move I'm using an accelerate towards behavior (only way to get it to move towards a magnet point). This doesnt work however because with gravity it will accelerate differently horizontally and vertically! I've tried a bunch of different ways to temporarily disable gravity but none of them work! Any ideas?

Best Answer

  • gyroscopegyroscope I am here.Posts: 6,598
    Accepted Answer


    Hi @pxlpfct

    You're correct that the gravity attribute itself can't be switched on or off during gameplay, so using accelerate is a good workaround. Firstly, make sure that you've 0 and 0 in the X and Y of the Gravity attribute in your scene (Scene > Attributes > Gravity).

    What's then needed is the good ol' boolean switch. You'll need one for each of your boxes. So something like when your bullet hits one of the boxes,

    When bullet overlaps or collides with Box1
    Change Attribute Switch1 to true


    When bullet overlaps or collides with Box2
    Change Attribute Switch2 to true

    --------etc.

    And then in each of your box Rules:

    When Switch(---number) is true)
    Accellerate Relative to Scene
    ----set to 270 for downwards, if I've understood correctly.

    That sort of thing; with experimentation based on what I've written, it should work out for you, hopefully.

    ----------------------------------------------
    http://davidgriffinapps.co.uk/

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

Answers

  • pxlpfctpxlpfct Member Posts: 37
    Thanks, I'll try, will accept later if it works :D
  • pxlpfctpxlpfct Member Posts: 37
    Thanks! Ended up doing it with the charged? boolean
Sign In or Register to comment.