Playmaker Forum

PlayMaker News => General Discussion => Topic started by: perdido007 on December 15, 2013, 02:28:53 AM

Title: distance travelled by player
Post by: perdido007 on December 15, 2013, 02: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
Title: Re: distance travelled by player
Post by: Lane on December 15, 2013, 02: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.
Title: Re: distance travelled by player
Post by: jeanfabre on December 15, 2013, 05: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

Title: Re: distance travelled by player
Post by: perdido007 on December 15, 2013, 11: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
Title: Re: distance travelled by player
Post by: Lane on December 15, 2013, 11: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 =)
Title: Re: distance travelled by player
Post by: perdido007 on December 15, 2013, 12:08:06 PM
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...
Title: Re: distance travelled by player
Post by: perdido007 on December 16, 2013, 12:22:15 PM
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...
Title: Re: distance travelled by player
Post by: Lane on December 16, 2013, 12:39:19 PM
You can use Float Round (http://hutonggames.com/playmakerforum/index.php?topic=2073.msg9110#msg9110) 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.
Title: Re: distance travelled by player
Post by: perdido007 on December 16, 2013, 12:51:28 PM
Once again Lane thank you for speedy reply, will go down this road and let you know, cheers
Title: Re: distance travelled by player
Post by: perdido007 on December 17, 2013, 01:39:42 AM
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...
Title: Re: distance travelled by player
Post by: Lane on December 17, 2013, 07: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 =)