Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: mikejkelley on October 06, 2015, 09:18:07 AM

Title: Cycle selection of enemies based on proximity[SOLVED]
Post by: mikejkelley on October 06, 2015, 09: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.
Title: Re: Get Next Closest Enemy (or why no Array List Add Every Frame?)
Post by: mikejkelley on October 10, 2015, 09:28:19 AM
Is there a better way to cycle through enemies based on their proximity (other than ArrayMaker)?
Title: Re: Get Next Closest Enemy (or why no Array List Add Every Frame?)
Post by: mikejkelley on October 14, 2015, 03:50:42 AM
Nobody has every needed to cycle through enemies based on proximity?
Title: Re: Cycle selection of enemies based on proximity
Post by: jeanfabre on October 14, 2015, 07: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
Title: Re: Cycle selection of enemies based on proximity
Post by: mikejkelley on October 14, 2015, 10: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 (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!
Title: Re: Cycle selection of enemies based on proximity
Post by: jeanfabre on October 15, 2015, 09:43:51 AM
Hi,

 ArrayListSort use the internal .NET sort function (https://msdn.microsoft.com/en-us/library/8k6e334t(v=vs.110).aspx), so it's no good for complex sorting, like distance.


Bye,

 Jean
Title: Re: Cycle selection of enemies based on proximity
Post by: mikejkelley on October 15, 2015, 09:50:28 AM
Hi Jean,

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

Title: Re: Cycle selection of enemies based on proximity
Post by: jeanfabre on October 16, 2015, 07: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
Title: Re: Cycle selection of enemies based on proximity
Post by: mikejkelley on October 16, 2015, 08:01:40 AM
Hi Jean,

That would be great. I've installed the beta.
Title: Re: Cycle selection of enemies based on proximity
Post by: mikejkelley on October 28, 2015, 05:51:24 PM
Has anyone else tried the new Array List Sort Game Object By Distance Action? I can't get it to work.
Title: Re: Cycle selection of enemies based on proximity
Post by: jeanfabre on October 29, 2015, 06: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
Title: Re: Cycle selection of enemies based on proximity
Post by: mikejkelley on October 29, 2015, 02:00:27 PM
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/sortDistPrefab.jpg)

http://www.nickelcitypixels.com/ArrayMakerDynamicDistanceSortingAction.unitypackage (http://www.nickelcitypixels.com/ArrayMakerDynamicDistanceSortingAction.unitypackage)
Title: Re: Cycle selection of enemies based on proximity
Post by: jeanfabre on October 30, 2015, 01:51:12 AM
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
Title: Re: Cycle selection of enemies based on proximity
Post by: mikejkelley on October 30, 2015, 02:29:54 AM
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.
Title: Re: Cycle selection of enemies based on proximity
Post by: jeanfabre on October 30, 2015, 02:09:19 PM
Hi,

 I think you forgot to attached the package, right?

 Bye,

 Jean
Title: Re: Cycle selection of enemies based on proximity
Post by: mikejkelley on October 30, 2015, 02:17:32 PM
Hi Jean,

It was in the previous post, I'll link again.
http://www.nickelcitypixels.com/ArrayMakerDynamicDistanceSortingAction.unitypackage (http://www.nickelcitypixels.com/ArrayMakerDynamicDistanceSortingAction.unitypackage)
Thanks as always!
Title: Re: Cycle selection of enemies based on proximity
Post by: jeanfabre on November 02, 2015, 03:36:28 AM
Hi,

 ok, so maybe I am not understandsing what you want.

 this action assumes that you define a number of GameObjects in an arrayList so that they can be sorted by distance, but you seem to expect that it search within the hieararchy and store directly objects ? correct?

for this I would use ArrayListFindGameObjectsByTag ( and all your ennemies woudl be tagged "Ennemy"), and then you'll have your arrayList populated.

 but really, since they are ennemies, you'll have do to a lot of house keeping, everytime an ennemy is created or deleted. so I would suggest that ennemies add themselves to this array AND remove themselved when killed.

 Bye,

 Jean
Title: Re: Cycle selection of enemies based on proximity
Post by: mikejkelley on November 02, 2015, 09:28:57 AM
Hi Jean,

I need to add enemies to an array dynamically and then sort them continuously according to their distance from the player. This is needed for the purpose of cycling selection.

So far I can do anyone of these things separately but not in conjunction. For example, adding enemies dynamically by tag prohibits me from sorting them by distance (the Sort By Distance Action has no effect on the resulting array).

I can do this in code but ultimately I'd like to incld. a Playmaker tutorial on this subj. in my course. BTW, once the add and sort problems are fixed I foresee trouble w/ the cycling selection process...
Title: Re: Cycle selection of enemies based on proximity
Post by: mikejkelley on November 02, 2015, 05:58:04 PM
This is the behavior I'm trying to achieve (after spawning the enemies into an array);
Title: Re: Cycle selection of enemies based on proximity
Post by: mikejkelley on November 06, 2015, 03:14:10 PM
So basically cycling selection of enemies (dynamically, from a spawn pool) based on proximity. 
Title: Re: Cycle selection of enemies based on proximity
Post by: jeanfabre on November 07, 2015, 01:53:32 PM
Hi,

 sorry, will deal with this next week, haven't had time to look at this properly yet... please keep bumping :)

 Bye,

 Jean
Title: Re: Cycle selection of enemies based on proximity
Post by: mikejkelley on November 12, 2015, 05:56:19 PM
OK, will do, thanks!
Title: Re: Cycle selection of enemies based on proximity
Post by: mikejkelley on November 16, 2015, 04:21:56 PM
Bump!
Title: Re: Cycle selection of enemies based on proximity
Post by: mikejkelley on November 22, 2015, 10:09:21 PM
bump!
Title: Re: Cycle selection of enemies based on proximity
Post by: mikejkelley on December 04, 2015, 03:50:33 AM
Bump! Hi Jean, you had said to msg you for a .unitypackage example, I did. Thanks! Hope to hear back soon.
Title: Re: Cycle selection of enemies based on proximity
Post by: jeanfabre on January 26, 2016, 07:47:02 AM
Hi,

 Did I made some progress on your case? don't hesitate to bump me, I have so many things to do, that I need reminders :)

Bye,

 Jean
Title: Re: Cycle selection of enemies based on proximity
Post by: mikejkelley on January 29, 2016, 03:44:30 PM
Hi Jean,

Yes, thank you it was very helpful (that doesn't mean I won't have questions later on lol). Thanks again, I understand you're super busy and I know what that's like!
Title: Re: Cycle selection of enemies based on proximity
Post by: jeanfabre on May 25, 2016, 04:05:15 AM
Hi,

 Good. Yes, never take it personally if I seem to have skipped something, simply bump.

I'll tag this thread solved.

 Bye,

 Jean