playMaker

Author Topic: ArrayList Find GameObjects Inside Collider  (Read 12917 times)

agelvik

  • Beta Group
  • Playmaker Newbie
  • *
  • Posts: 46
Re: ArrayList Find GameObjects Inside Collider
« Reply #15 on: February 24, 2019, 10:11:17 AM »
Tested both of them and the 2D action by far gives the best and most accurate results! :D I didn't notice much of a difference with the 3D tho. Made some gifs to show it on my end:

3D action
https://www.dropbox.com/s/xr6tahiotwtn3im/hitbox_issue.gif?dl=0

2D action
https://www.dropbox.com/s/7m2i3g9em1wf54s/hitbox_2d.gif?dl=0


Also got some errors after I imported the 2D action. In line 104-110 there were some converting issues. I simply removed the if-else-endif lines and only kept:

Collider2D[] results = new Collider2D[99];
col.OverlapCollider(filter, results);

Worked fine after that!

I guess I'll do a combination of 3D and 2D physics, it seems to work to have Rigidbody on-top of the hierarchy and Rigidbody2D further down lol. Even tho it's a 2D game I feel I have a lot more control and flexibility when using 3D components haha.

Here's the full message from console btw, in case you want the full thing:

The best overloaded method match for `UnityEngine.Collider2D.OverlapCollider(UnityEngine.ContactFilter2D, UnityEngine.Collider2D[])' has some invalid arguments
error CS1502: Assets/PlayMaker Custom Actions/ArrayMaker/ListGameObjectsInsideCollider2D.cs(106,8)

Argument `#2' cannot convert `System.Collections.Generic.List<UnityEngine.Collider2D>' expression to type `UnityEngine.Collider2D[]'
error CS1503: Assets/PlayMaker Custom Actions/ArrayMaker/ListGameObjectsInsideCollider2D.cs(106,32)

Using unity version 2018.2.10f1

Deek

  • Full Member
  • ***
  • Posts: 133
Re: ArrayList Find GameObjects Inside Collider
« Reply #16 on: February 24, 2019, 11:01:28 AM »
To improve the accuracy of box colliders on the 3D version is quite a pain, though it did improve a bit from the previous version. Maybe someone could point out how to do it better, but for now I think it's okay enough, since it only affects the area around the corners when rotation the GameObject.

I added these define conditions to the 2D version when I realised that using lists for the built-in function OverlapCollider() is only available in a later Unity version, but because the Unity docs don't say which version added that feature, I was hoping that it was somewhere after 2017 and added backwards-compatibility by providing a big empty array (being less performant and more limiting than a list). It seems to have been added somewhere between Unity 2018.3 and the 2019 beta, which I used when trying to improve these actions.

It might be a good idea to stick to either 2D or 3D physics for your game, to prevent any problems down the line, and I think there isn't that much that you can do with the 3D components that you can't do with the 2D ones. You actually have more options on 2D colliders for example, that are also more catered to the world of 2D, just like the behavior of 2D Physics. Also you would need to maintain both the 'Physics' and 'Physics 2D' Project Settings when making changes to the general parameters and collision matrices. Just a tip to remove the headache when you one day wonder why those two colliders don't react to one another.  ;)

Your game/prototype looks awesome by the way, I really like the hit effect on the enemies and bounciness of the character!

I'm just gonna fix that error on the 2D version by specifying a higher Unity version and call it a day. Maybe I'll improve upon the 3D one in the future.

agelvik

  • Beta Group
  • Playmaker Newbie
  • *
  • Posts: 46
Re: ArrayList Find GameObjects Inside Collider
« Reply #17 on: February 24, 2019, 03:05:47 PM »
Yeah can understand it's a bit tricky to get it fixed, but right now the 2D action works just fine for what I need which is what matters. :) Thanks for giving it an update in such a short notice, especially since this thread is like 1 year old haha.

Thanks for your tips & kind words about the game btw!