- Home /
 
               Question by 
               NYP · Feb 03, 2014 at 09:26 PM · 
                2dplatformerlinecastgrounded  
              
 
              Unable to check if grounded
Hello, I am just starting out in Unity and UnityScript and am trying to check if my 2D platform sprite is grounded. I am having trouble implementing the code from the 2d tutorial demo and have looked at a number of answers on here but must be doing something wrong as it's still not working. Here is my code:
 private var groundCheck : Transform;
 private var isGrounded : boolean;
 
 function Start () {
 
 groundCheck = transform.Find("groundCheck");
 
 }
 
 function Update () {
 
     isGrounded= Physics2D.Linecast(transform.position, groundCheck.position, 1 << LayerMask.NameToLayer("Ground"));  
     Debug.Log(isGrounded);
 }
It doesn't matter where my player is, isGrounded always returns False.
All help greatly appreciated
               Comment
              
 
               
              Are your player and the ground on the same sorting layer/ order in layer? That could be an issue.
Answer by falconer · Nov 15, 2014 at 07:51 PM
Here is an article I found which explains how to use Physics.OverlapCircle to check if object is grounded. Maybe it might help someone who is struggling to get this
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                