- Home /
 
               Question by 
               RAV3R · Nov 17, 2020 at 10:34 AM · 
                physicsrigidbodyground detection  
              
 
              Checking ground not working as expected
Hi, Im checking ground so i can add a force down when isnt on ground. The problem is that my GameObjects flickers when on ground. I desactivate the "use gravity" in the rigidbody, but it stills flickering. This is the code i have for that force down.
 void FixedUpdate()
     {
         if (!isGround)
         {
             rb.AddForce(Vector3.up * -gravityForceMultiplier * 50);
         }
         else
         {
             rb.AddForce(Vector3.up * -normalGravity);
         }
     }
And this is the code for raycasting.
 private void Update()
     {
         if (Physics.Raycast(this.transform.position, Vector3.down, disToGround, groundLayer))
         {
             isGround = true;
         }
         else
         {
             isGround = false;
         }     
     }
Thanks and sorry for my bad English.
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by RAV3R · Nov 17, 2020 at 11:33 AM
I managed to solve the problem by adding a little offset to the raycast, so the code results in:
    private void Update()
     {
         if (Physics.Raycast(this.transform.position + new Vector3(0, 0.2f, 0), Vector3.down, disToGround, groundLayer))
         {
             isGround = true;
         }
         else
         {
             isGround = false;
         }        
     }
 
  
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
               
 
			 
                