- Home /
Question by
stilesini · Jul 15, 2016 at 03:20 AM ·
raycast2d-platformerbooleanground detection
No response from raycast
I am still new to unity so forgive me if this is a stupid question.
I am creating movement for a player class for a 2D platformer. I am now implementing jumping for the player so I am using a Raycast to detect if the player is on the ground.
My problem is that I have a bool function which creates a ray from the center of a collider on the player to just below the player and then returns true or false depending on if the ray hits an object.
I then set a bool variable called grounded to what the function returns but it does not seem to be working
Is there anything I am doing wrong?
This is the bool function
bool isGrounded()
{
return Physics.Raycast(playerCollider.offset, Vector2.down, playerCollider.radius + 1);
}
This is where I set the grounded variable
grounded = isGrounded();
The playerCollider variable is set in the start function
playerCollider = GetComponent<CircleCollider2D>();
Comment