Raycast Check in GetKey?
I've been developing a character controller from scratch and have manged to get the ground checking working, however when I go to step off a ledge my character continues to float in the direction of travel, and slowly falls downward, instead of plummeting. I think the issues lies in the fact that I can't check for raycast hit while moving and the key is down.
My code for raycasting and checking for the ground is as follows:
 RaycastHit2D hit = Physics2D.Raycast(transform.position, Vector2.down, 0.55f);
 Debug.DrawLine(transform.position,new Vector2(transform.position.x,transform.position.y-0.55f),Color.red);
 
 if (hit) {
     if (hit.collider.tag == "ground"){
         isJumping = false;
     }
 
     if (hit.collider.tag == null){
         Debug.Log ("There is no ground!");
         isJumping = true;
     }
 }
My code for moving left is as follows (rb is my rigidbody):
 if (Input.GetKey (KeyCode.A) && isJumping == false) {
     rb.MovePosition(rb.position + -horizontalVelocity * Time.fixedDeltaTime);
 }
Any help would be appreciated!
Your answer
 
 
             Follow this Question
Related Questions
Controller script active on both characters. 1 Answer
How can I get vector coordinates from a raycast relative to an object? 0 Answers
MoveTowards is curving for no reason 0 Answers
How to stop player from moving forward when they run into a wall? 0 Answers
How to move whilst airborne (using standard third person character script)? 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                