GameSalad

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Distance travelled in pixels

Hello, pls i want to measure total distance of main actor in pixels which moves all over the scene ( left, right, up down from some start position). I found topics that people advice to use magnitude (startx-selfpositionx, starty-selfpositiony). I try that, but when actor returning back to start position the distance goes down, but i need increase it even its returning back. Is there a simple was to do that ? Thank for your help. And sorry for my English.

Comments

  • tatiangtatiang Posts: 11,845Member, Sous Chef, PRO, Senior Sous-Chef
    edited March 2016

    Speed in Gamesalad is measured in pixels per second.

    If you know the actor's speed or since you can determine it using the linear velocity self attributes, you can just do something like this:

    Timer every 1 second
         Change attribute game.distance to game.distance+[actor speed]

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

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

    @tatiang said:
    Speed in Gamesalad is measured in pixels per second.

    If you know the actor's speed or since you can determine it using the linear velocity self attributes, you can just do something like this:

    Timer every 1 second
         Change attribute game.distance to game.distance+[actor speed]

    I was thinking along the same lines too, to use speed.

    Otherwise if the speed is not know (for example the actor is being dragged around the screen) then you could do something like this:

    3 real attributes
    Distance
    Record X
    Record Y

    Change Record X to self X
    Change Record Y to self Y
    Timer - Every 0.1 seconds
    --Change Distance to Distance+magnitude(self X-Record X, self Y-Record Y)
    --Change Record X to self X
    --Change Record Y to self Y

  • prazakgs1prazakgs1 Posts: 2Member

    @Socks said:

    @tatiang said:
    Speed in Gamesalad is measured in pixels per second.

    If you know the actor's speed or since you can determine it using the linear velocity self attributes, you can just do something like this:

    Timer every 1 second
         Change attribute game.distance to game.distance+[actor speed]

    I was thinking along the same lines too, to use speed.

    Otherwise if the speed is not know (for example the actor is being dragged around the screen) then you could do something like this:

    3 real attributes
    Distance
    Record X
    Record Y

    Change Record X to self X
    Change Record Y to self Y
    Timer - Every 0.1 seconds
    --Change Distance to Distance+magnitude(self X-Record X, self Y-Record Y)
    --Change Record X to self X
    --Change Record Y to self Y

    Hi, thank you for your replies, i tryed both (as i already measure speed) and Socks's code fits my needs more. Great community support !!!! Thanks again.

  • The_Gamesalad_GuruThe_Gamesalad_Guru Posts: 9,913Member
    edited April 2016

    I show how to do this in my GS physics series. Using the loop behavior gives a more accurate result.

Sign In or Register to comment.