- Home /
Did it another way around.
External Physics2D.OverlapCircle check not working.
I wrote this piece of code inside an abstract class:
public bool IsPlayerInRange (Transform transform, float range)
{
return Physics2D.OverlapCircle(transform.position, range, LayerMask.NameToLayer("Player"), Mathf.Infinity, Mathf.Infinity);
}
And then I wrote this inside another class that inherited from the abstract class:
if (IsPlayerInRange(transform, 4))
Rbody2D.DashSides(stats.movement_speed * 2, 0.2f, false);
But somehow it doesn't check for the player. Why? Thanks in advance.
Consider name collision then. Your transform parameter might be interfering with the one from the monobehaviour class
Answer by Buckslice · Nov 29, 2017 at 09:25 PM
the minDepth argument for Physics2D.OverlapCircle should be negative infinity probably
I've always done it this way and... Well, it always worked for me. But I've always used Physics2D.OverlapCircle directly to its purposes. Never like this, as a boolean method inside an abstract class...
Outside of the abstract class it works well, but when I bring the checker to the inside of it, well, then it doesn't work.
Hmm thats weird, are you getting null reference exceptions or something? $$anonymous$$aybe post some more code
No... Not any null references. But now I've decided to give up and use a faster solution: not using Physics2D.OverlapCircle inside both FixedUpdate and LateUpdate at the same time. I'm using an EmptyObject with a Trigger CircleCollider right now, that returns what I want... :)
I'm such a bug creator - can't solve bugs guy... Anyway, thanks for trying. I'm closing this question now.
Follow this Question
Related Questions
Where should I call Physics2D.Raycast ? 0 Answers
checking Bool true from another Script? 2 Answers
groundCheck in small beginner project not working properly 0 Answers
How to change a Bool for only a single prefab GameObject? 1 Answer
How can I slow the velocity of my player without it affecting fall speed? 0 Answers