Hey, all!
I need to tell if my character is moving uphill or downhill and change the speed accordingly. However, when I debug my values, the normal of the last measurement is ALWAYS identical to the normal of the current one. Is there something wrong with my code?
Thanks!- YA
void Align( Transform player, RaycastHit2D hit ){
float groundAngle = Vector3.Angle ( Vector3.up, hit.normal);
Debug.Log ( "Last angle was: " + lastAngle );
Debug.Log ("This angle is: " + groundAngle );
if( groundAngle < angleLimit ){
//Align player to surface norma
player.transform.rotation = Quaternion.FromToRotation ( Vector3.up, hit.normal );
float newSpeed = moveSpeed + ((groundAngle/angleLimit)*Mathf.Sign( groundAngle*lastAngle ))*speedFlux;
transform.Translate( newSpeed*Time.deltaTime*Input.GetAxisRaw ("Horizontal"), 0, 0);
//Move player
Vector3 newPos = new Vector3( transform.position.x, hit.point.y-0.1f, transform.position.z);
//Stick to face on y axis
transform.position = newPos;
lastAngle = groundAngle;
Debug.Log ( "New speed is: " + newSpeed );
}
else Debug.Log("POOP");
}