playMaker

Author Topic: [SOLVED] ArrayMaker - Get Farthest Actions  (Read 2184 times)

Chizzler

  • Junior Playmaker
  • **
  • Posts: 67
[SOLVED] ArrayMaker - Get Farthest Actions
« on: January 19, 2016, 12:31:10 PM »
Hey. I'm having trouble with the array maker actions;

Get farthest Game Object
Get farthest Game Object in Sight

Both actions are returning the closest game object.

I Set up a quick scene to reproduce the issue with 12 spheres (children of an empty game object) and a player model.
First I find the player game object and store it in a variable, then an array of the spheres is created at runtime using a "next Child loop" on the empty game object. This is all working as expected.

When i run the action(s) above though, the closest sphere is selected, rather than the furthest. I can move the character around, and it will update, but always with the closest sphere.

Obviously I wanted to make sure it was calculating distances correctly, so I tried using the "Sort Array by distance" action, and that works correctly, so theoretically i could work around the issue by sorting the array and selecting the last index value, but this seems like an expensive way around it.

Is it a problem with the action? or am I doing something wrong?

P.S.  Naturally, i've updated to the latest version of ArrayMaker (Jan 2016).

Edit: creating the array at runtime isn't necessary to reproduce the issue, a pre-filled array of the spheres has the same issue
« Last Edit: January 19, 2016, 05:50:38 PM by Chizzler »

Chizzler

  • Junior Playmaker
  • **
  • Posts: 67
Re: ArrayMaker - Get Farthest Actions
« Reply #1 on: January 19, 2016, 05:47:26 PM »
Okay, After scratching my head for a while, I looked into the code and have solved the problem with the actions. Not sure if something went wrong with my files, or it's a mistake with ArrayMaker, but just in case others run into the problem:

Solution (ArrayListGetFarthestGameObject.cs)

Line 96: Replace
Code: [Select]
float sqrDist = Mathf.Infinity;
With
Code: [Select]
float sqrDist = 0.0f;
Line 106: Replace
Code: [Select]
if (sqrDistTest<= sqrDist)
With
Code: [Select]
if (sqrDistTest>= sqrDist)
Solution (ArrayListGetFarthestGameObjectInSight.cs)

Line 115: Replace
Code: [Select]
float sqrDist = Mathf.Infinity;
With
Code: [Select]
float sqrDist = 0.0f;
Line 125: Replace
Code: [Select]
if (sqrDistTest<= sqrDist)
With
Code: [Select]
if (sqrDistTest>= sqrDist)
« Last Edit: January 19, 2016, 06:16:09 PM by Chizzler »

mdotstrange

  • Hero Member
  • *****
  • Posts: 555
    • Can't code? Who cares! Make games anyway!
Re: [SOLVED] ArrayMaker - Get Farthest Actions
« Reply #2 on: January 19, 2016, 07:28:55 PM »
Thanks for posting your fix! I had tried this action in the past-couldn't get it to work and tried another solution- so thank you  :)
Indie game dev and instructor at the Strange School. Learn Playmaker at the Strange School!

Chizzler

  • Junior Playmaker
  • **
  • Posts: 67
Re: [SOLVED] ArrayMaker - Get Farthest Actions
« Reply #3 on: January 19, 2016, 08:53:47 PM »
Glad to hear it wasn't just me ;D  Happy to help.