playMaker

Author Topic: How to a store colliders under different names?[SOLVED]  (Read 2381 times)

Neikke

  • Full Member
  • ***
  • Posts: 134
How to a store colliders under different names?[SOLVED]
« on: July 15, 2019, 10:36:45 PM »
Hi,

I need to make objects my Player collides with - stored as object variables which I can do by enabling Store Collider checkbox in Trigger Event action. But the problem is If Player collides with Object A and Object B which are right next to each other, Object A is stored as collider only for a second until Player collides with Object B leaving Object A inaccessible. And if I want to Send Event to both objects initiating some FSMs that are on both Objects - only the last one is affected of course. How can I make stored colliders to be named and stored under unique name variables? Thanks!
« Last Edit: July 26, 2019, 04:15:14 AM by jeanfabre »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: How to a tore colliders under different names?
« Reply #1 on: July 16, 2019, 03:36:29 AM »
Hi,

 you can store the collider in an array everytime you get a collision, this will give you an ordered list of the collisions.

the key here is not to use one variable per collider, but an array, that's important. then you can adopt rules like first in last out, or first in first out which defines the order and management of your array.

Bye,

 Jean

Neikke

  • Full Member
  • ***
  • Posts: 134
Re: How to a tore colliders under different names?
« Reply #2 on: July 17, 2019, 01:11:47 PM »
Thanks for replying Jean! Could you please break it down a bit more for me?

Current Situation: I'm doing infinite runner type of game. I have three Boxes standing right next to each other. Each time Player collides with one of those Boxes - I'm calling an FSM on Box's Parent to Spawn some Random Powerup at Player's position. This Powerup floats above the Player character for some time being parented to a Player and after a second disappears.

Problem: The problem is when I'm colliding with three boxes lying on the ground very close to each other - all three Powerups fly out almost at the same time covering and interpenetrating each other. This happens because I'm calling Spawn Random Powerup immediately each time Player is colliding with the boxes. And what I want is to have Spawned Powerups to appear one after the other even though Boxes were already destroyed - so that Players would clearly see what they got from the box.

Question: How do I set up such an Array, where fast collision with all three boxes will spawn the Powerup of the first Box immediately, but delaying the Powerups of others till the First Powerup is gone completely?

Thanks a lot for reading all of this!
« Last Edit: July 17, 2019, 01:17:08 PM by Neikke »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: How to a store colliders under different names?
« Reply #3 on: July 18, 2019, 02:06:07 AM »
Hi,

 the key is to delay the spawning using the index in the array as multiplier of the delay value.


 so if you find that you have 3 colliders in the array, you spawn the first one instantly, spawn the second one 0.3f later, the third one, 0.6,

so the math is i*0.3 i being the index in the array.

does that make sense?

one way to do this is to have a fsm that checks every 0.3 seconds the array and take out the first item always.

Bye,

 Jean

Neikke

  • Full Member
  • ***
  • Posts: 134
Re: How to a store colliders under different names?
« Reply #4 on: July 18, 2019, 11:52:24 AM »
the key is to delay the spawning using the index in the array as multiplier of the delay value.


so if you find that you have 3 colliders in the array, you spawn the first one instantly, spawn the second one 0.3f later, the third one, 0.6,

so the math is i*0.3 i being the index in the array.

does that make sense?

This sounds very good and exactly what I need but where should I set up this i*0.3 multiplying of indexes and in which action (and in which field) particularly it should happen? Is it in Array Get Next action? How should I make so the first one goes out instantly and others with this 0.3 delay? By delaying do you mean using Wait action?

one way to do this is to have a fsm that checks every 0.3 seconds the array and take out the first item always.

Checking if the Array list is empty every 0.3 sec is a good idea but I have a few questions:

1) Is it ok for performance to do this check that often since I'm aiming for mobile platforms?

2) Wouldn't it be better to send the command to start checking if the Array list is empty only on collision with the first box? And the somehow stop it so it's not checking regularly?

3) How can I check if Array list is empty? I heard from Djaydino that there is action ArrayListIsEmpty2, I even tried importing it from Ecosystem but it gave me lots of errors in Unity 2019.1.7f1 so I had to delete it. Are there any other ways to do that?

Thanks a lot man!
« Last Edit: July 18, 2019, 12:01:06 PM by Neikke »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: How to a store colliders under different names?
« Reply #5 on: July 19, 2019, 03:50:12 AM »
Hi,

 there are tons of ways to implement this delay.

- in the iterate itself, you wait before the next step
- as you send event, you put a delay in the event sending action
- using the index, each receiver object could implement its delay, all would receive the event at the right time only they would delay their own animations by themselves ( more complex, don't recommand it for your case)

1: the check doesn't cost much, just check the length of the array and only do something if it's greate than 0, that's it.

2: no, you will miss the potential following collisions. The best is to use this array with first in first out rule. just populate the array without caring about the next step, and have an fsm that also react on collision and if the array is only 1 object, fire instantly, else go through a iteration with a delay until the array

3: you are confusing ArrayList and the built in FsmArray variable. Use ArrayLength if you are using FsmArray

Bye,

 Jean

Neikke

  • Full Member
  • ***
  • Posts: 134
Re: How to a store colliders under different names?
« Reply #6 on: July 19, 2019, 05:16:14 AM »
Tnanks Jean, but what is first in first out rule you were mentioning? How do I do it?

Currently I'm just adding objects I'm colliding with to Array using Array Add action which just adds new object to the end of the list. Then I'm looping through the array and triggering events I need on each item in the Array. Is it what you mean?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: How to a store colliders under different names?
« Reply #7 on: July 24, 2019, 02:02:24 AM »
Hi,

First in first out ( aka FIFO ):

this is a technic of dealing with the content of the array and how you deal with processing it:

so the first item you put in your array MUST be the first item you process and remove from your array.

let's say you add 3 values, in sequence, first you add A, then you add B, then C, you end up with:

[A,B,C]

the FIFO rules means that you must take A first, process it and delete it, you end up with:

[B,C]

so FIFO rules means: add value at the end of the array, but remove the first value always until array is empty.


now, the other variant is Last in, First Out( AKA LIFO)

[A,B,C]

with LIFO, I would take C first, ending up with

[A,B]

does that make more sense?

the FIFO rules means the first item you have added is of most importance, so for triggers in a level this make sense, your character is going through several coins, you add them as they come, but you treat them in order in which they were added.

Bye,

 Jean

Neikke

  • Full Member
  • ***
  • Posts: 134
Re: How to a store colliders under different names?
« Reply #8 on: July 25, 2019, 10:35:55 AM »
Thanks for this detailed explaining Jean! I appreciate it a lot! But what's not clear enough for me is how and where exactly do I actually specify whether I want to use FIFO or LIFO? For example how can I implement FIFO technic using Array List Get Next action? Which additional actions should I use? For example Array List Remove At (index) or do you mean some other action? Cos now it seems like I'm not using any of those concepts at all in my Array List setup.

Here's how I currently have it set up: I'm just looping through items in my Array list triggering events on each of them (without removing any first or last ones of them meanwhile), and when all items are processed from A to C and the Finish event is sent I'm forwarding it to the State where I have Array List Clear  action which just clears contents of my Array list and returns to the State where I'm checking if there are any new items added to the Array List Proxy.

Am I doing it wrong? What should I do to actually implement this FIFOs and LIFOs? Thanks a lot in advance!

« Last Edit: July 25, 2019, 10:43:50 AM by Neikke »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: How to a store colliders under different names?
« Reply #9 on: July 26, 2019, 02:06:10 AM »
Hi,

 Don't overthink this, FIFO and LIFO are mouthfull concept that simply explain how you want to add and take items in an array.

FIFO must take the first element, which is alwasy element at index 0, so FIFO means using ArrayAdd to add an element and ArrayGetAtIndex(0) when you want to take one and remove it straight away ( removeAt(0) )

if you are using getNext action, it means that you want to process in one go items in order, this is still FIFO, so you are good, however the slight incorrect protocole here is that you should always remove the item you pick. It's of course not mandatory, and it all depends on how your logic operate, if you fsm operating the getnext loop is being disabled, then you are compromising the FIFO process, but in your case it may not matter.

Bye,

 Jean



Neikke

  • Full Member
  • ***
  • Posts: 134
Re: How to a store colliders under different names?
« Reply #10 on: July 26, 2019, 03:07:45 AM »
Thanks a lot Jean! Now I got it!