Problem with Raycast ? (4.3)

Hello,

I joint a short video about my question 1419832–74668–$movement.mp4.zip (1.57 MB)

I use a raycast (down) to track a normal and create a forward vector.
On video rays are :
red > normal
blue > forward vector
cyan > raycast

But when my character climb an incline, sometimes the normal seems good, sometimes not … Is this a bug ? Or did I miss something ?

Thx for your help … 4.2 to 4.3 is not easy sometimes.

There is the code :

//Collide with ground
		groundedHit = Physics2D.Raycast(transform.position, -Vector2.up, lenghtToGround, 1 << LayerMask.NameToLayer("Ground"));
		forwardVect = rot90 * groundedHit.normal;			//Rotate to have forward Vector
		forwardVect = forwardVect.normalized;				
		
		//Init movement vector
		mvtVect = forwardVect * mvtDir * speedMax;
		if(!grounded) {										//If gounded > gravity
			mvtVect.y -= gravity;
		}
		
		//Animation
		cAnim.SetFloat("speed",Mathf.Abs(mvtDir));			//Trigger to "Run"
		
		//Movement
		rigidbody2D.velocity = mvtVect * MainVar.fixedDeltaTime;
		
		//DEBUG
		Debug.DrawRay(transform.position, groundedHit.normal, Color.red);					//Normal
		Debug.DrawRay(transform.position, forwardVect, Color.blue);							//Forward vector
		Debug.DrawRay(transform.position, -Vector2.up * lenghtToGround, Color.cyan);		//RayCast

Found a solution …

I moved the Raycast source.
Vector2(transform.position.x, transform.position.y+0.3F)

I think that sometimes, Raycast source was ‘in’ the ground.

It seems to work.