Distance Traveled and 8-Direction

Get help using Construct 2

Post » Sun Mar 16, 2014 4:05 pm

I'd like to calculate the distance the player has traveled over the course of the game for a stat. The hero is controlled with the 8 direction behavior. How can I track the distance traveled if I know his speed every tick from 8 direction?

(Sorry, this is a "I'm in the 7th day of the game jam and I'm having trouble thinking about math properly" question.)
B
11
S
2
Posts: 87
Reputation: 1,112

Post » Sun Mar 16, 2014 4:25 pm

hmm.It seems that there is nothing for that right now.
What kind of game are you trying to make?
We may find an easier way if you tell
I will not let you reach the sisters
Nature Forums
B
11
S
5
G
2
Posts: 496
Reputation: 2,306

Post » Sun Mar 16, 2014 4:37 pm

It's not that hard. I think. On top of my head:

Lets say your character moves with wasd keys. First you could setup a series of condition that detect these input.
Have the player object have lastx and last y instance variables.
Add a global variable named totaldistance.
Then, under every (direction input) condition call

totaldistance = totaldistance + distance(player.lastx, player.lasty,player.x,player.Y)
player.lastx = player.x
player.lasty = player.y


this means, every time you press w, a, s, d, system will check the distance of lastx, lasty position, add to totaldistance, and set new lastx and lasty positions. I hope I could explain it.
B
18
S
4
G
1
Posts: 332
Reputation: 3,149

Post » Mon Mar 17, 2014 8:42 am

That seems right. @Wertle,can you try that to see if it works?
I will not let you reach the sisters
Nature Forums
B
11
S
5
G
2
Posts: 496
Reputation: 2,306

Post » Mon Mar 17, 2014 8:20 pm

@Windwalker Actually i was thinking of something much simpler, which of course came to me after a good night's sleep after the jam was over :D

DistanceTraveled += Hero.8Direction.Speed*dt

It wasn't a critical stat or anything so no big deal, it was just driving me crazy that I couldn't think of it!
B
11
S
2
Posts: 87
Reputation: 1,112


Return to How do I....?

Who is online

Users browsing this forum: brunopalermo, JackTYGA, MeteoorSC, worm1 and 21 guests