Distance travelled in pixels
prazakgs1
Member Posts: 2
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
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
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.
I show how to do this in my GS physics series. Using the loop behavior gives a more accurate result.
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS