How to Simulate distance travelled?

Hi Guys and Gals, I'm trying to simulate distance travelled in my game but I can't seem to get it to work.

I'm trying to just simply do,

when any

self.positionX = self.positionX+50

when self.positionY = self.positionY+50

when self.positionX = self.positionX-50

when self.positionY = self.positionY-50

change miles to miles+1

But this doesn't seem to work, I'm not looking for anything super advanced just something simple that works.

Any ideas guys? Thanks in advance :)

Comments

  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772
    If the character were always moving, like in an endless runner you could just start a timer and say every X number of seconds add 1 to Miles.

    If the character isn't always moving but you're using some sort of movement controls, like the keyboard. You could add to Miles whenever a movement key is pressed.
  • EireStudiosEireStudios Member Posts: 451
    It's a top down boat game and I'm using a joystick to control the player, two good ideas mate but I'd like to do something along the lines of 50 pixels = 1 mile
  • KevinCrossKevinCross London, UKMember Posts: 1,894
    Is the boat constantly moving forward? Would you want to check miles if they go left and right constantly, or is it for monitoring fuel etc?
  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772
    Here is a little demo I put together that should work. It only keeps track if you move to the right by holding down the arrow key, but it should give you the info you need I hope.
  • natzuurnatzuur Member Posts: 304
    Create attribute LastX, LastY, Miles, and Self.Distancefrom

    Constrain Self.DistanceFrom to magnitude(SelfX-LastX, SelfY-LastY)

    At the start
    Change Last X to Self X.
    Change Last Y to Self Y.

    When attribute self.distancefrom is greater than 50
    Change Miles to Miles +1
    Change Last X to Self X.
    Change Last Y to Self Y.

    Think that should do it so it tracks in all directions, cant test right now though.


  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772
    Yep, that is basically what the demo is I posted. :)
  • natzuurnatzuur Member Posts: 304
    Yep, that is basically what the demo is I posted. :)
    Nice. @Soulstealer Well there ya go, demo and all!

  • EireStudiosEireStudios Member Posts: 451
    Thanks guys, I won't get a chance to test it until tomorrow but I think that's exactly what I'm looking for :)
  • JagonAppsJagonApps Member Posts: 241
    @Soulstealer So, did it work?
  • EireStudiosEireStudios Member Posts: 451
    @JagonApps yes.. works perfect! Thanks again guys :)
  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772
    awesome, you're welcome.
Sign In or Register to comment.