Sorry i’m newbie in unity. i have two problem. I using c#.
(1) I have tried to create a function to check the player is grounded or not, but it is still does not work.
bool grounded = false;
public Transform groundCheck;
float groundRadius = 0.2f;
public LayerMask isGround;
//----------------------------------------------------------
void fixUpdate (){
grounded = Physics2D.OverlapCircle (groundCheck.position, groundRadius, isGround);
animator.SetBool ("Ground", grounded);
}
Screen Shoot :
(2) And I want to ask, how to check the Object that ground in different areas. for the example i have a character and two areas A and B, how to know that my character on area A or B? (c #)
mitananda:
Sorry i’m newbie in unity. i have two problem. I using c#.
(1) I have tried to create a function to check the player is grounded or not, but it is still does not work.
bool grounded = false;
public Transform groundCheck;
float groundRadius = 0.2f;
public LayerMask isGround;
//----------------------------------------------------------
void fixUpdate (){
grounded = Physics2D.OverlapCircle (groundCheck.position, groundRadius, isGround);
animator.SetBool ("Ground", grounded);
}
Screen Shoot :
(2) And I want to ask, how to check the Object that ground in different areas. for the example i have a character and two areas A and B, how to know that my character on area A or B? (c #)
If you are using a CharacterController there is the CharacterController.isGrounded option?
Otherwise, You can use raycast to detect the floor collision or an empty gameObject as a child with a Box collider underneath your character.
Then run a OnTriggerEnter or OnTriggerStay.
Theres also the option to use Points and Normal to find the location of the collision on your character, if it uses a collider not set as trigger.