playMaker

Author Topic: Cycle selection of enemies based on proximity[SOLVED]  (Read 5806 times)

mikejkelley

  • Full Member
  • ***
  • Posts: 136
    • View Profile
Cycle selection of enemies based on proximity[SOLVED]
« on: October 06, 2015, 06:18:07 AM »
I have three enemies swarming the player. I want the player to be able to select the closest enemy by pressing the space bar. If he/she presses the space bar again, the second closest enemy is selected. If he/she presses the space bar a third time the third closest enemy is selected.

I have an array. All the prefabs add to the array successfully and are arranged according to their distance.

The problem is I don't see a way to continually update the list (as the distances change) since there's no Every Frame checkbox.

I'm new to ArrayMaker.
« Last Edit: May 25, 2016, 01:05:28 AM by jeanfabre »

mikejkelley

  • Full Member
  • ***
  • Posts: 136
    • View Profile
Re: Get Next Closest Enemy (or why no Array List Add Every Frame?)
« Reply #1 on: October 10, 2015, 06:28:19 AM »
Is there a better way to cycle through enemies based on their proximity (other than ArrayMaker)?

mikejkelley

  • Full Member
  • ***
  • Posts: 136
    • View Profile
Re: Get Next Closest Enemy (or why no Array List Add Every Frame?)
« Reply #2 on: October 14, 2015, 12:50:42 AM »
Nobody has every needed to cycle through enemies based on proximity?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14109
  • Official Playmaker Support
    • View Profile
Re: Cycle selection of enemies based on proximity
« Reply #3 on: October 14, 2015, 04:14:54 AM »
Hi,

 Indeed many do :)

To achieve this, you can loop your state using a "next frame event" and so you achieve an everyframe system on every actions, including the one without a built in option.

Can you try this and let me know how it goes?

 Bye,

 Jean

mikejkelley

  • Full Member
  • ***
  • Posts: 136
    • View Profile
Re: Cycle selection of enemies based on proximity
« Reply #4 on: October 14, 2015, 07:04:07 AM »
That solves every frame. But why is that different from using a FINISHED Transition and looping back into the State?

Can you explain the Array List Sort Action? I'm attempting to sort GameObjects according to distance and Array List Sort has No Discernable Effect in my scene.

http://www.nickelcitypixels.com/cycleSelectionProximity.unitypackage

Also while you're here, can you PM me a mailing address so that I can send you the Tobii EyeX hardware? Also also can you tell Alex that I'll be talking to the publisher this week and I'd like to give them an update? Thanks!
« Last Edit: October 14, 2015, 07:07:27 AM by mikejkelley »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14109
  • Official Playmaker Support
    • View Profile
Re: Cycle selection of enemies based on proximity
« Reply #5 on: October 15, 2015, 06:43:51 AM »
Hi,

 ArrayListSort use the internal .NET sort function, so it's no good for complex sorting, like distance.


Bye,

 Jean

mikejkelley

  • Full Member
  • ***
  • Posts: 136
    • View Profile
Re: Cycle selection of enemies based on proximity
« Reply #6 on: October 15, 2015, 06:50:28 AM »
Hi Jean,

Thanks as always for your insight! Can you suggest a workaround? Thanks.


jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14109
  • Official Playmaker Support
    • View Profile
Re: Cycle selection of enemies based on proximity
« Reply #7 on: October 16, 2015, 04:44:31 AM »
Hi,

 yep, the workaround is to have a next frame event and loop through your list to arrange them. I have a working sample, but it's for 1.8, do you have access to the beta? else, I'll quickly refactor it for current PlayMaker version and send it over.

 Bye,

 Jean

mikejkelley

  • Full Member
  • ***
  • Posts: 136
    • View Profile
Re: Cycle selection of enemies based on proximity
« Reply #8 on: October 16, 2015, 05:01:40 AM »
Hi Jean,

That would be great. I've installed the beta.
« Last Edit: October 16, 2015, 10:50:54 AM by mikejkelley »

mikejkelley

  • Full Member
  • ***
  • Posts: 136
    • View Profile
Re: Cycle selection of enemies based on proximity
« Reply #9 on: October 28, 2015, 02:51:24 PM »
Has anyone else tried the new Array List Sort Game Object By Distance Action? I can't get it to work.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14109
  • Official Playmaker Support
    • View Profile
Re: Cycle selection of enemies based on proximity
« Reply #10 on: October 29, 2015, 03:21:34 AM »
Hi,

 Made a quick test scene to demonstrate this action.

 it's very crude, but get the job done. move the sphere and you'll see the arrayList of cubes being reordered to match by distance from the sphere.

Let me know if you still have trouble understanding its use.

 Bye,

 Jean

mikejkelley

  • Full Member
  • ***
  • Posts: 136
    • View Profile
Re: Cycle selection of enemies based on proximity
« Reply #11 on: October 29, 2015, 11:00:27 AM »
Hi Jean,

Thanks for the Action and example! Unfortunately what I need to do is update the array dynamically using prefabs from an object pool. This doesn't seem to do the trick:


http://www.nickelcitypixels.com/ArrayMakerDynamicDistanceSortingAction.unitypackage

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14109
  • Official Playmaker Support
    • View Profile
Re: Cycle selection of enemies based on proximity
« Reply #12 on: October 29, 2015, 10:51:12 PM »
Hi,

 this is not related and should not be a problem. you can add remove items in the ArrayList and then call this sorting actions, it will work.

Everytime you add/remove an ennemy you add it to this array, and the action will take that in consideration the next time it's processed.


 Bye,

 Jean

mikejkelley

  • Full Member
  • ***
  • Posts: 136
    • View Profile
Re: Cycle selection of enemies based on proximity
« Reply #13 on: October 29, 2015, 11:29:54 PM »
Hi Jean,

Thanks once again for your reply. To clarify; I understand it shouldn't be a problem, but it is a problem. If you look at the linked package, the Array List Add action isn't adding the Prefab to the ArrayList.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14109
  • Official Playmaker Support
    • View Profile
Re: Cycle selection of enemies based on proximity
« Reply #14 on: October 30, 2015, 11:09:19 AM »
Hi,

 I think you forgot to attached the package, right?

 Bye,

 Jean