How do I make a button accelerate my actor (car)?

zSuperChargedzzSuperChargedz Member Posts: 19
edited March 2012 in Working with GS (Mac)
I'm trying to make a button accelerate the car. How do I make it so when I press the button on the screen it accelerates the car forward? How do I connect the two?

btw I have the button on the screen and the car rotates with my joy stick, but how do I make it so the button accelerates it? (also it would be great if you could also tell me how the other button brakes the car)

Best Answer

  • JohnPapiomitisJohnPapiomitis Posts: 6,256
    Accepted Answer
    You connect the two with game attributes.

    Make a game attribute called go, make it a boolean.

    In your button have when touch is pressed
    -change attribute go to true
    Then in the otherwise section of that rule put a change attribute behavior and change attribte go to false.

    Then in your car have a rule when attribute go=true
    -accelerate

Answers

  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    No, have it exactly how i posted above.

    In your button:

    Rule: When touch is pressed
    -change attribute game.go to true
    OTHERWISE
    -change attribute game.go to false

    In your car:
    Rule: when attribute game.go=true
    -accelerate behavior
  • zSuperChargedzzSuperChargedz Member Posts: 19
    Still not working, but check this picture of the car, I left the button the same but this is how I changed the car:

    http://imageshack.us/photo/my-images/546/screenshot20120323at100.png/
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    Whats not working, if you followed my post itll work.

    And the car rule is good now
  • zSuperChargedzzSuperChargedz Member Posts: 19
    Okay, well if it's good I don't understand why it's not working.. anything thing else that might have gone wrong or something else I could do?
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    edited March 2012
    You need to change your rule in the button to when touch is pressed then add a change attribute go to true plus You're accelerate needs to be relative to scene not actor. Also if you're using gravity you might need more speed. You didn't follow John's instructions as you said you didn't change the button rules as he showed you and then you wonder why it didn't work.
  • CloudsClouds Member Posts: 1,599
    edited March 2012
    did I do it correctly?
    No, have it exactly how i posted above.
    I left the button the same . . .
    I don't understand why it's not working..

    Translation:

    A) Here's the code for my button and car - are they both right ?
    B) No, they need to look like this (provides the code)
    A) Ok . . you know my code for the button which you said was wrong . . .
    B) Yeah . . .
    A) Well, I kept that wrong code and guess what . .
    B) What . . .
    A) It still doesn't work.



    :))
  • MotherHooseMotherHoose Member Posts: 2,456
    on Button:
    Rule: when
    Event: touch is pressed
    --changeAttribute: game.accelerate To: true
    Otherwise:
    --changeAttribute: game.accelerate To: false

    on Car:
    Rule: when
    Attribute: game.Accelerate = true
    --accelerate behaviors (as @FryingBaconStudios instructed)
    Otherwise:
    --stop behaviors

    image MH
  • zSuperChargedzzSuperChargedz Member Posts: 19
    Okay I followed all the instructions, the button looks exactly how motherhoose said, and on the car it's exactly the same except which behavior? There's only one Stop behavior which is Stop Music, but which exact one do I use, or do I have to make a custom one? Here are the photos again of both the car and button, can you tell me what's wrong about it other than the missing behavior?

    Car:
    http://imageshack.us/photo/my-images/714/screenshot20120324at105.png/

    Button:
    http://imageshack.us/photo/my-images/542/screenshot20120324at105.png/
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    edited March 2012
    You still didnt follow the instructions..

    In your button all is good, except you need a change attribute behavior in the main part of the rule as well, changing attribute.go to true. Leave the otherwise section how you have it.
  • zSuperChargedzzSuperChargedz Member Posts: 19
    can you take a screenshot of what it should like? because I'm changing it to true now, and the car moves but automatically, can you take a screen shot?
  • adalpilscazaadalpilscaza Member Posts: 44
    http://www.mediafire.com/?sgraprqqfcbca24 I think this is what John means.
  • zSuperChargedzzSuperChargedz Member Posts: 19
    thanks a lot! this helped a lot, now it can accelerate, the only problem though once the button is pressed it doesn't slow down :/ it just keeps going and going..
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    If you mean when you let go of the button you want it to slow down then add drag to the car under its physics attributes.
  • zSuperChargedzzSuperChargedz Member Posts: 19
    so it should look like this:

    Attribute____self.Physics.Drag____=____0

    ??
  • zSuperChargedzzSuperChargedz Member Posts: 19
    as a new rule ^
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    No, go into the actor, on the left youll see its attribute. Go into physics, go to drag, and put in number so its not 0. 50 is probably a good starting point.

    Also for future references, you cant change an actors physics atttributes in game with a change attribute behavior or anything.
  • zSuperChargedzzSuperChargedz Member Posts: 19
    thanks dude, this helped a lot
  • zSuperChargedzzSuperChargedz Member Posts: 19
    its finally working :D
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    @zsupercharedz it would help if you spent some time watching the videos and studying the cookbook so you can learn the basics as it seems you lack that knowledge.
Sign In or Register to comment.