- Home /
Boolean doesn't change at start position.
Hello, I have pressed a key and toggled this function:
bool IsGrounded()
{
if(Physics.Raycast(transform.position, Vector3.down * 0.75f))
{
print("YES");
return true;
}
else
{
print("NO");
return false;
}
}
I use this function to check if I am grounded. It works when I go off platform, but when I am above platform over the 0.75f ray lenght limit it still returns as if I am still grounded. What am I doing wrong? Thank you.
Answer by xxmariofer · Mar 05, 2019 at 12:17 PM
because your raycast lenght is infinite, try this line (the vector is only the direction)
if(Physics.Raycast(transform.position, Vector3.down, 0.75f))
Thanks. However, why can I then use this in update and not in the boolean return function?:
if(Physics.Raycast(transform.position, Vector3.down * 0.75f))
{
}
i didnt understand your question, physics raycast returns a bool depending if it hitted something so you can return it in a method like this
public bool Example()
{
return Physics.Raycast(transform.position, Vector3.down, 0.7f);
}
Your answer
Follow this Question
Related Questions
Long-distance physics 0 Answers
Rigidbody.position causes shaking 1 Answer
Realistic Bow and Arrow Physics? 2 Answers
How to aim a ball with cross hair? 2 Answers
Raycast On Rigidbody 1 Answer