Hi, I’m trying to make a double jump using Raycast. Sounds pretty simple, but for a reason my raycast hit all the time, and returns true even if there’s nothing else in the scene and I’d like to know why.
Here is my code :
public class CharacterControls : MonoBehaviour {
private Rigidbody2D _rb;
[SerializeField]
private float _speed;
[SerializeField]
private float _jumpForce;
private Collider2D _coll;
void Update()
{
Debug.Log(Grounded());
if (Grounded())
{
Debug.Log("Grouded");
}
else
{
Debug.Log("Oh Oh");
}
bool Grounded()
{
return (Physics2D.Raycast(transform.position,Vector2.down,_coll.bounds.extents.y + 0.1f));
}
}
What I’m trying to acheive is that the raycast goes down, with a distance just a bit lower than the collider. For a reason though, even if there is no ground, nothing else than the character in fact, Grounded() is always true. More than that, I can put any distance I want, even negative ones, and it will be true. What I’m doing wrong?
Thanks for the help!