- Home /
Question by
Neuxz · Jun 04, 2020 at 03:27 PM ·
raycastraycastingraycasthitphysics.raycast
Raycast hit in OnDrawGizmos but not in Update
Hi iv'e got this wiered issue that my Raycast to the ground ist true in OnDrawGizmos but false in Update.
private Ray GroundRay
{
get => new Ray(transform.position, Vector3.down * MaxGoundDistance);
}
private bool IsGrounded
{
get => Physics.Raycast(GroundRay, MaxGoundDistance);
}
private void OnDrawGizmos()
{
Gizmos.color = IsGrounded ? Color.red : Color.blue;
Gizmos.DrawRay(GroundRay);
}
void Update()
{
if (IsGrounded)
{
Debug.Log("Grounded" + verticalMotion);
}
else
{
Debug.Log("AirTime" + verticalMotion);
}
}
Any ideas or workarounds to fix this and get an constant result out of it?
Comment
Best Answer
Answer by a-ivanov · Jul 07, 2020 at 07:36 PM
Rearrange your logic so that Physics.Raycast is called inside MonoBehaviour.FixedUpdate() exclusively. This is true for all physics-related Unity API.