playMaker

Author Topic: [SOLVED]Follow player position (with array)  (Read 1986 times)

Vanyfraise

  • Playmaker Newbie
  • *
  • Posts: 19
[SOLVED]Follow player position (with array)
« on: May 24, 2018, 11:00:10 AM »
    Hi guys,

    I want to do this in my shmup :

Pods are moving to the last player position saved.


To find a way do this and with 600 help on the discord, i tried this solution. On the player gameobject :
  • State 1 : Check player axis  (if vector3 = 0 , then player is not moving)
  • State 2 : wait 0.16 second
  • State 3 : Add Player's transform.position vector 3 in an array list.

Then, on the first pod :
  • State 1 : Check if is moving (again, i know).
  • State 2 : Get the next array of the player transform position vector 3 array and set a vector3 with his values.
  • State 3 : Move pod to this new vector3 (i'll change the move toward with an iTween Move To later).

For now, the pod is moving all along the list of elements in the array (which is infinite for now) and loop...

How can I delete an element after using it ?
Of course if you have any ideas to do this linear following tricks w/o array, i'd loved to read it.

Thanks ![/list]
« Last Edit: May 28, 2018, 10:16:27 AM by Vanyfraise »

Wolfride

  • Playmaker Newbie
  • *
  • Posts: 11
Re: Follow player position (with array)
« Reply #1 on: May 25, 2018, 07:38:34 AM »
My 'simple but might work' thought is have two global transitions. One when a key is up (player isn't putting input to move) and another when input is received. Without input/movement have the drones stop. When the player inputs to move (button/key/joystick), fire a global transition to move the drones again. The second drone just follows the first drone instead of the player. Just get position of whatever it is following every frame, or do a 'get position', move to position (itween), on finish, check input/no input. If no input, go to a state that waits for the global transition. If still input, get position.

So the drones will stop the moment the player stops and move the moment the player moves. If they move the same speed as the player, they won't 'catch' the player theoretically?

No array required.

Edit: You could also make an empty game object as a child of the player, or a cube with a collider and no mesh renderer, and use it's transform as a target to keep the drones farther away.
« Last Edit: May 25, 2018, 07:43:09 AM by Wolfride »

Vanyfraise

  • Playmaker Newbie
  • *
  • Posts: 19
Re: Follow player position (with array)
« Reply #2 on: May 25, 2018, 07:55:57 AM »
If i do that, the drone will be "stuck" at the "whatever it is following every frame" transform position), no ?

I mean, with your proposition and depending where i put this "whatever", drone will go on that guy. If i put it behind, drone will go behind, or i want the "whatever" position change depending player.

Sorry, it's already kinda hard to explain in my native language so in english... :D

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Follow player position (with array)
« Reply #3 on: May 25, 2018, 10:08:42 AM »
Hi.
I made a sample of what i think you are trying to achieve.
I don't have time atm to make a video, but i did add some documentation.

It should be fine to try on your project, but just to be sure, try on a new project or make a backup from your project.
(Package contains 1 scene and 1 custom action)

let me know if it is good.

Vanyfraise

  • Playmaker Newbie
  • *
  • Posts: 19
Re: Follow player position (with array)
« Reply #4 on: May 28, 2018, 05:09:47 AM »
Thanks a lot Djaydino !

I put your FSMs in my project. I have to make some adaptation but it's a pretty good start !

For now, my folowers join themselfs after few movements :

Vanyfraise

  • Playmaker Newbie
  • *
  • Posts: 19
Re: Follow player position (with array)
« Reply #5 on: May 28, 2018, 05:28:52 AM »
If i take the folower1 "final" position give it to folower 2 as "move toward" objective, it works fine.

I have to polish all these but it's definitly a good start !

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: [SOLVED]Follow player position (with array)
« Reply #6 on: May 31, 2018, 06:48:15 PM »
Hi.
I am happy it helped you out.

and good luck with polishing more :D