1

I have a problem with Physcis2D.OverlapCircle. In one tutorial i saw somebody use it as ground detector. I am trying to use it as something that checks if player is on top of a platform or not. What i did is i created empty gameObject on each platform. Then i put a script on it where i wrote:

 public bool onTop;
 public LayerMask whatIsTop;
 public float topCheckRadius;
 public Transform topCheck;

 void FixeUpdate()
 {
 onTop = Physics2D.OverlapCircle(topCheck.position, topCheckRadius, whatIsTop);
 if (onTop)
 {
     Debug.Log("Works!");
 }
 }

Then in inspector i put the empty GameObject as the topCheck.position, i put some value for the topCheckRadius and lastly i created a layer called Top and then i selected it in the WhatIsTop layermask.

But when i jump on the platform with player nothing happens.

Richarrd82
  • 97
  • 2
  • 11

2 Answers2

0

Hi i think this may help 2d-check-if-player-is-on-the-ground

tell me how you get on :)

bool isGrounded = false;
public Transform GroundCheck1; // Put the prefab of the ground here
public LayerMask groundLayer; // Insert the layer here.

void Update() {
    isGrounded = Physics2D.OverlapCircle(GroundCheck1.position, 0.15f, groundLayer); 
    // checks if you are within 0.15 position in the Y of the ground
}
R1CH101
  • 60
  • 8
0

I know that this may be not relevant anymore, But I noticed you have a typo on the Callback method FixedUpdate() You wrote FixeUpdate() have a nice day!