How to: Number of meters being drifted

allc1865allc1865 Member, PRO Posts: 777

Hello :)

How can I make it so that whenever my car drifts it shows the number of meters that are being drifted?

Thanks guys ;)

Best Answers

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

    Hi @allc1865 it does depend on a couple of other factors based on your game file.... but let's assume you're talking about drift to the left or right along the x axis.

    Then you need to decide how many pixels you want to represent a metre. For this example, let's assume 60 pixels to a metre. Make a real attribute called Drift; an integer attribute called SpotXpos (this is the straight ahead point without any drift)

    Constrain Attribute Drift to abs(SpotXpos-Car.Position.X)/60

    So if you wanted to display the drift in the scene, set up a Display Text behaviour with

    scene.Drift.." metres" or similar in its text to show.

    That should do it, untested though.

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

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

    Good question, OK, thinking it through, I guess you'll be putting the constrain attribute in the car actor - which is moving - you possibly don't want the display text to move, or be shown on the car....

    So put the Display Text behaviour in its own actor, if you like, as a display to show the drift.

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

Answers

  • allc1865allc1865 Member, PRO Posts: 777

    @gyroscope‌, thanks for your reply
    So, just so I understand, do I put scene.Drift in the same place that the constrain attribute went or do I create a separate actor and put the display text behavior in there?

  • allc1865allc1865 Member, PRO Posts: 777

    @gyroscope‌, thank you :)

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited April 2014

    @allc1865 sent me a DM, he doesnt mind me copying and pasting his question in this thread:

    Hi, gyroscope, you answered a question of mine a while ago and I was hoping that you could help me a bit on this.

    This topic is on this thread here: http://forums.gamesalad.com/discussion/65931/how-to-number-of-meters-being-drifted

    So the solution you gave me worked, however whenever I drift, the numbers just keep going - they keep adding up. They never stop and then disappear like I had wanted them to. I was just wondering if there was a way to fix this?

    I appreciate your help

    Hi @allc1865 although I didn't test the solution I gave you (or perhaps I did, I really can't remember...) providing you choose the abs function from the expression editor, the equation

    abs(SpotXpos-Car.Position.X)/60

    should work, in other words the Drift number should rise or fall without problem depending on how close or how far you are from the midpoint (called SpotXpos). Hope that helps...

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

  • allc1865allc1865 Member, PRO Posts: 777

    Hi, @gyroscope,
    My apologies, I didn't realize you didn't answer questions via private messages.

    I did try abs(SpotXpos-Car.Position.X)/60 and it works, however the numbers keep adding up even when the car isn't moving. Like I said, it never stops, so I was wondering how to fix that.

    Thanks for your reply :)

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited April 2014

    Hi @allc1885 Still not sure why you're getting that result...

    Here's a test file, to show drift (60 pixels for every metre) left and right; check it out, hopefully you can see what you've done differently in your file:

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

  • allc1865allc1865 Member, PRO Posts: 777

    hi @gyroscope, thank you for the template! It does help & I see where I went wrong.
    The question I do have is that the drift meters start counting whenever the car moves. I think I could fix this is by putting this:
    when left is true and game.speed is > 200, change attribute scene.drift to true.
    This would work but my actors are not instances so I can't add the 'scene' part to that...So do you know how to get around this?

    Thanks for your help!

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited April 2014

    I'd suggest that the car is actually stationary, and make your background (road) move to simulate the car moving (there's couple of ways to do this, including parallax scrolling, worth checking out in tutorial files that are about).

    This way you're just concerned with drift left and right, with the car's apparent forward movement having no effect.

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

  • allc1865allc1865 Member, PRO Posts: 777

    @gyroscope, hi - this is a top view of the car where the player controls the car turning in all different directions on the race track; the car isn't stationary. This game isn't something like Mad Cab :)

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited April 2014

    I see, so you mean you can see the complete race track on the screen that the car is driven around? In that case, you're in "more advanced territory" - I'd have to think about that now... but also there are a few variations that could influence the best way to go about a solution for that now... would you mind posting your game file to me to have a look?

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

  • allc1865allc1865 Member, PRO Posts: 777
Sign In or Register to comment.