playMaker

Author Topic: Array get closest game object in sight (2D)  (Read 411 times)

serenefox

  • Full Member
  • ***
  • Posts: 125
    • View Profile
    • Serenefox Games
Array get closest game object in sight (2D)
« on: December 31, 2018, 07:34:15 PM »
I decided to make a separate thread on this topic. I tried this action from the ecosystem but I soon figured out that the line cast is done in 3d physics and I need it for 2d. I tried to modify the script to work with 2D but I was unsuccessful. The documentation on the line cast doesn’t use “out” so I am unsure what to do.

Thanks!
Most Recent Published Games:
Don't Pop! Dungeon - iOS/Android

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14014
  • Official Playmaker Support
    • View Profile
Re: Array get closest game object in sight (2D)
« Reply #1 on: January 09, 2019, 10:30:40 PM »
Hi Shane,

Ok, I'll work on this. I'll ping you later on today when it's done.

Bye,

 Jean

serenefox

  • Full Member
  • ***
  • Posts: 125
    • View Profile
    • Serenefox Games
Re: Array get closest game object in sight (2D)
« Reply #2 on: January 10, 2019, 10:31:24 AM »
Awesome! Thanks Jean!
Most Recent Published Games:
Don't Pop! Dungeon - iOS/Android

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14014
  • Official Playmaker Support
    • View Profile
Re: Array get closest game object in sight (2D)
« Reply #3 on: January 11, 2019, 12:37:08 AM »
Hi,

 ok, I edited the action and added a new option to use physics 2d, so please redownload from the ecosystem ( I moved the action from U4 to U5 repository as well).

Let me know how it goes, it works well for me here.

 Bye,

 Jean

serenefox

  • Full Member
  • ***
  • Posts: 125
    • View Profile
    • Serenefox Games
Re: Array get closest game object in sight (2D)
« Reply #4 on: January 11, 2019, 04:38:27 PM »
Thanks Jean, I am having a problem though. I can't get the "closest Gameobject"'s value. It is always "none". With or without layermasks. I tried to use a debug.log but it didn't show up in the console either. Is there anyway to see what the linecast is hitting?
Most Recent Published Games:
Don't Pop! Dungeon - iOS/Android

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14014
  • Official Playmaker Support
    • View Profile
Re: Array get closest game object in sight (2D)
« Reply #5 on: January 13, 2019, 11:36:45 PM »
Hi,

 It's odd, It all works fine here:



 can you try an a test scene like me? you did put a 2d collider on your sprites right? and checked the "Use 2d physics" in the action?

Bye,

 Jean

serenefox

  • Full Member
  • ***
  • Posts: 125
    • View Profile
    • Serenefox Games
Re: Array get closest game object in sight (2D)
« Reply #6 on: January 13, 2019, 11:52:50 PM »
Hey Jean,

It works for me in a fresh scene but in my current game scene it must be blocked by something, which is why I was wondering if there was some way of testing what the ray/linecast is hitting. I also turned off “queries hit triggers” too and it still doesn’t work in my game scene. And yeah I do have 2d colliders and checked 2d physics.
Most Recent Published Games:
Don't Pop! Dungeon - iOS/Android

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14014
  • Official Playmaker Support
    • View Profile
Re: Array get closest game object in sight (2D)
« Reply #7 on: January 14, 2019, 12:19:52 AM »
Hi,

 well, this is in "sight" so yeah, it means it has to be the first hit.

you need to first make sure what is blocking, and probably edit the physics collision matrix to avoid clashes between various 2d objects or yours. Organize your stuff by layers and make them ignore each other based on their context.

else, it would mean a different approach and a new action for that which would be more a regular GetClosestObject period, right?

Bye,

 Jean


Bye,

 Jean

serenefox

  • Full Member
  • ***
  • Posts: 125
    • View Profile
    • Serenefox Games
Re: Array get closest game object in sight (2D)
« Reply #8 on: January 14, 2019, 10:24:17 AM »
Hi Jean,

I eventually had to give up on the action and did it like it is pictured in my image below, it works for me even though I am not getting the closest enemy in the array. I am not sure why its not working, as far as I know my 2D collision matrix is fine. Also there isn't even any collision boxes in between the AI and the enemy. Thank you for taking the time to help me though I really appreciate it!
Most Recent Published Games:
Don't Pop! Dungeon - iOS/Android