# playMaker

### Author Topic: distance travelled by player  (Read 4163 times)

#### perdido007

• Playmaker Newbie
• Posts: 24
##### distance travelled by player
« on: December 15, 2013, 12:28:53 AM »
Hello, complete newbie, how would i calculate distance travelled by player on a platform 2d, and how would i display it on screen via a gui, which actions should i use to set up the fsm, i cannot find tutorial for this, should i use navmesh as this looks too sophisticated for something like this, am at a loss here, thanks in advance for any help, cheers

#### Lane

• Hero Member
• Posts: 2488
• Yup.
##### Re: distance travelled by player
« Reply #1 on: December 15, 2013, 12:59:21 AM »
The difficulty is somewhat circumstantial. Can the player travel backers for instance? If not, then you only need the position of one axis.

if you're a complete newbie arent there more fundamental problems to address? Just kind of curious.

#### jeanfabre

• Hero Member
• Posts: 14342
• Official Playmaker Support
##### Re: distance travelled by player
« Reply #2 on: December 15, 2013, 03:12:03 AM »
Hi,

if you are looking for a general "progress" indicator, use the the distance from the player compared to its starting point ( it can be an actuall empty gameobject), and that distance is very representative of the true distance travelled without having to consider movement noises such as back and forth, jumpts, etc etc.

If you are looking for a precise pedometer, the distance is the sum of ALL delta movements. so have an FSM that every frame adds the delta movement to a total  distance variable, and that will be the true travelled distance. for this use the action "get position" and substract it from the previous position, then use the action "Get vector length" to find out that distance between the current position and the last position, add that length to the total distance variable, and finally inject the current position to the previous position variable. All this in one state basically.

If you have trouble understanding or implementing, let me know.

Bye,

Jean

#### perdido007

• Playmaker Newbie
• Posts: 24
##### Re: distance travelled by player
« Reply #3 on: December 15, 2013, 09:04:14 AM »
Thank you for the speedy reply, will try the one axis approach and will let you know as i go.To answer Lane yes just the one direction as player is a car on a highway and can only go forwards and not backwards. Thanking Jean also for such a detailed and very positive attitude answer will definitely keep you posted. Cheers

#### Lane

• Hero Member
• Posts: 2488
• Yup.
##### Re: distance travelled by player
« Reply #4 on: December 15, 2013, 09:18:03 AM »
Yup for a infinite scroller type game you can just Get Position and store the axis you need into a float, assuming the player starts at the 0 position. If he's not starting at 0 then you can still use it, just put a dummy object at 0 and subtract the distance from the player.

Welcome to the forum, btw =)

#### perdido007

• Playmaker Newbie
• Posts: 24
##### Re: distance travelled by player
« Reply #5 on: December 15, 2013, 10:08:06 AM »
Thank you Lane, am going down that road now, am faffing around but it's part of the process i suppose, thanking you again for allow up...

#### perdido007

• Playmaker Newbie
• Posts: 24
##### Re: distance travelled by player
« Reply #6 on: December 16, 2013, 10:22:15 AM »
Ok…after much searching have found it using the 3 variables in the picture….and the distance is depicted in the GUI…how the heck do i change that into something with just 2 numbers after the decimal, am searching in the GUI variables am i right to go down that road…? thanking again for help...

#### Lane

• Hero Member
• Posts: 2488
• Yup.
##### Re: distance travelled by player
« Reply #7 on: December 16, 2013, 10:39:19 AM »
You can use Float Round or convert it to an Int.

For the GUI stuff what you're doing there works fine. You can also use the GUI Layout actions just the same but they can be confusing at first if you haven't worked with the GUI before.
« Last Edit: December 16, 2013, 10:47:36 AM by Lane »

#### perdido007

• Playmaker Newbie
• Posts: 24
##### Re: distance travelled by player
« Reply #8 on: December 16, 2013, 10:51:28 AM »
Once again Lane thank you for speedy reply, will go down this road and let you know, cheers

#### perdido007

• Playmaker Newbie
• Posts: 24
##### Re: distance travelled by player
« Reply #9 on: December 16, 2013, 11:39:42 PM »
OK got it working, phew that was interesting. A couple of ideas as way of a clear up since i did not find it clear at first but this is what i did and would i be right :
1) checked your link to the script add on from Jean Fabre, downloaded it and imported it into the playmaker folder in unity
2) euh, now what, tried to open my FSM in MonoDevelop but no go,
3) checked the actions tab in the FSM in unity and there was the advised and downloaded action, fiddled a bit in the state and bob's your uncle.
Was this the correct manner to proceed ? If so then that part of your forum "Share New Actions" should be a gold mine…for the code diggers and ditchers…
Thanking you again...

#### Lane

• Hero Member
• Posts: 2488
• Yup.
##### Re: distance travelled by player
« Reply #10 on: December 17, 2013, 05:01:32 AM »
Yup thats how its done. It's really easy to add new scripts from the 'goldmine', you can just download, drag it into Unity and it will Playmaker will automatically see it and add it to the list for use. It's easy peasy! Literally seconds =)