Question by
AlbertoVgdd · Feb 21, 2018 at 04:30 PM ·
colliderraycasthitphysics.raycastcapsulecollider
Problem dealing with RaycastHit.normal on collider edges
Hi, I'm working on a custom character controller for a third person camera which supports one-way slopes. It uses a capsule collider for physics (ground tests, avoid wall sticking....) My animator has these states at the moment: idle-Walk-Slide-Fall.
I am stuck now in the transition between different animation states. When the character falls off from the ground it starts playing the slide animation for a brief period of time before falling (instead of the fall animation directly).
At first I though that the problem was in my Animator Controller, but then I debuged the normals of the hits of the capsule cast. Do anyone know how can I fix this problem?
// CapsuleCast Below the player to determine the grounded/sliding state
raycastHitArray = CapsuleCastFromPlayer(Vector3.down,Mathf.Abs(Mathf.Min(playerRigidbody.velocity.y*Time.fixedDeltaTime,-0.01f)),environmentLayerMask.value);
// If the player is grounded asume the player is sliding too
if (raycastHitArray.Length > 0 )
{
playerGrounded = true;
playerSliding = true;
// Check if the player is not sliding from the closest plane to the furthest.
foreach(RaycastHit hit in raycastHitArray)
{
// Using hit.normal returns bad normals in the edges of the collider of the floor.
floorNormal = hit.normal;
Debug.DrawRay(hit.point,hit.normal,Color.red,5f);
if (Vector3.Angle(hit.normal, Vector3.up) < slopeAngle)
{
playerSliding = false;
break;
}
}
}
Comment