playMaker

Author Topic: arrayMaker sort position racing game  (Read 4849 times)

FritsLyn

  • Full Member
  • ***
  • Posts: 191
arrayMaker sort position racing game
« on: June 09, 2015, 07:16:35 AM »
Hi guys, am trying to get my head around this:

I have a sort of racing game, and I know the position of all my players, as a float (0 -> unlimited)

I'll have approx 10 opponents + the player simultaneously.

Every frame I need to update a classic racing game position in the corner:

---=== You are: 4 of 7 ===---

Now, since I need this to be fast and done every frame I'll need something not clumsy - which is all I can think of.

I'm pretty sure there's a 'native' way to do this, and any pointers would be highly appreciated.

I have my X players with individual n's - and for one Player every frame I need to know the position expressed as '[your position] of X'..

Thanks! :)
« Last Edit: June 09, 2015, 07:18:29 AM by FritsLyn »

sebaslive

  • Hero Member
  • *****
  • Posts: 572
    • Frame Tale Studios
Re: arrayMaker sort position racing game
« Reply #1 on: June 09, 2015, 11:26:32 AM »
Hey FritsLyn, I have never done a racing game but I googled positioning and it seems how it is usually done is by checkpoints and how close the player is to the checkpoint to set up each position.

http://answers.unity3d.com/questions/25189/race-position-help.html

It's going to be a bit of float compares with array sorts to get it but these tips are a good start to get you there.
All my VR games use Steam VR Playmaker Toolkit: http://u3d.as/u20
And Oculus Touch Playmaker Toolkit: http://u3d.as/QT5


Follow me @sebasRez

FritsLyn

  • Full Member
  • ***
  • Posts: 191
Re: arrayMaker sort position racing game
« Reply #2 on: June 10, 2015, 04:08:41 AM »
Hi Sebaslive,

Thanks for your attempt to answer, but I'm not sure you understood me:

I am aware of the 'ordinary' checkpoint approach - and other hacks on a 'standard' racing game where you do not know how far each player is.

I however know the position of all my players, as a float n (0 -> unlimited)

What I need to know is an elegant way to sort these and find Players rank (position on the chart), so I can write 'You are 2 of 10'.

So, to put it in another way, I need to:

* Sort my list of game objects (all racers) based on float n
* Look up a particular racer (player) to see his position on the list

Since Playmakers version of Sort is not opening for Linq or Comparison
https://msdn.microsoft.com/en-us/library/tfakywbh.aspx

- I do not know how to do this elegantly.

What I am doing is a self made loop-through-and-compare in FSM's but that is hardly optimal - and I need it every frame, so I need it to be optimized, and I do not know how to do that with PlayMakers Array functionality.

Thanks :)

sebaslive

  • Hero Member
  • *****
  • Posts: 572
    • Frame Tale Studios
Re: arrayMaker sort position racing game
« Reply #3 on: June 10, 2015, 11:52:42 AM »
Hi, so, what I meant is that when I usually need to see how to do something I try to see how others before have done it to not reinvent the wheel.

It will be much easier to see the process in the file I attached but to explain...

To be more specific I went ahead and created the process in my scene. I am currently using 4 racers for my scene but you can set it to ten and tweak the fsm. It's a big mess since I did it really quick but basically it gets the first child of the empty game object which are the racers and it gets their position on X.

It then sets the X into a new array for its position, then we need to set and reverse the order so that when it loops again it will set the positions in order. Next we set the actual racer in a new array based on the index order of the position it placed. Now that we set that order we can see which index it fell into and use that as the position.

Currently since it is grabbing the index, first place is 0. You can use int compares to set this or make a new array that lets you know which position means which.

Sorry if I am ever vague with the explanations but I just wanted to go through my process to how I try to find the solution.

I hope this helps!
All my VR games use Steam VR Playmaker Toolkit: http://u3d.as/u20
And Oculus Touch Playmaker Toolkit: http://u3d.as/QT5


Follow me @sebasRez

FritsLyn

  • Full Member
  • ***
  • Posts: 191
Re: arrayMaker sort position racing game
« Reply #4 on: June 11, 2015, 02:29:42 AM »
Hi again sebaslive,

Thanks a gain for your tremendous efforts.

It appears to me that in fact it is much easier and faster not to use an array then. (not via PlayMaker that is)

The purpose is not to use an array, but to get the 'ranking' as fast as possible, and via PlayMaker it then appears to me to be done best like this:

Set an int 'Position' to 1
Go through the other racers via FSM's and if they are ahead of me, increase position by 1.




sebaslive

  • Hero Member
  • *****
  • Posts: 572
    • Frame Tale Studios
Re: arrayMaker sort position racing game
« Reply #5 on: June 11, 2015, 07:11:48 AM »
awesome, glad to see you found a quicker way to do it.
All my VR games use Steam VR Playmaker Toolkit: http://u3d.as/u20
And Oculus Touch Playmaker Toolkit: http://u3d.as/QT5


Follow me @sebasRez

FritsLyn

  • Full Member
  • ***
  • Posts: 191
Re: arrayMaker sort position racing game
« Reply #6 on: June 11, 2015, 08:05:17 AM »
Lol, well, actually I do not think this is a very good way, I'm pretty sure an array would be better.

And my question was then: How this would be done elegantly with Playmakers handling of arrays.

I understand your solution, but IMO that was less elegant than my brute force.

So as I understand it, there's no way to do Comparison in Playmakers List - I think this is needed.

It is not a good thing to have to make workarounds like you showed me IMO, when it could all be done in Playmaker as a single action, if there was only a field to set up the Comparison.

sebaslive

  • Hero Member
  • *****
  • Posts: 572
    • Frame Tale Studios
Re: arrayMaker sort position racing game
« Reply #7 on: June 13, 2015, 09:59:05 PM »
oh, not sure of another way to do this but hopefully someone can help out with a new solution...
All my VR games use Steam VR Playmaker Toolkit: http://u3d.as/u20
And Oculus Touch Playmaker Toolkit: http://u3d.as/QT5


Follow me @sebasRez

LuminRabbit

  • Full Member
  • ***
  • Posts: 161
  • Lumin Rabbit
Re: arrayMaker sort position racing game
« Reply #8 on: October 07, 2020, 06:47:11 PM »
Hi, so, what I meant is that when I usually need to see how to do something I try to see how others before have done it to not reinvent the wheel.

It will be much easier to see the process in the file I attached but to explain...

To be more specific I went ahead and created the process in my scene. I am currently using 4 racers for my scene but you can set it to ten and tweak the fsm. It's a big mess since I did it really quick but basically it gets the first child of the empty game object which are the racers and it gets their position on X.

It then sets the X into a new array for its position, then we need to set and reverse the order so that when it loops again it will set the positions in order. Next we set the actual racer in a new array based on the index order of the position it placed. Now that we set that order we can see which index it fell into and use that as the position.

Currently since it is grabbing the index, first place is 0. You can use int compares to set this or make a new array that lets you know which position means which.

Sorry if I am ever vague with the explanations but I just wanted to go through my process to how I try to find the solution.

I hope this helps!

Hi sebaslive,

Any chance you could do an updated version? Id really like to see how this was done for learning purposes. The actions in the current project have been updated since so I cant get rid of the errors :P

If its too much trouble no worries though I think I understand the concept (trying to wrap my head around using multiple arrays and comparing things between them to get a result.
« Last Edit: October 07, 2020, 06:50:17 PM by Kodagames »
Have I said how much I love playmaker!!! This is one amazing tool