Problem with ethan prefab.
I do not know why but sometimes the third person character Ethan gets stuck on edges of things like a cube and floats in place. If I don't touch it for about a minute or two its like the gravity slowly takes over again.
I also cannot for the life of me understand why he wont use stairs. I just downloaded and tried to do the same test with Unity 5.5. Is there something wrong with the settings?
I would really appreciate some help with this.
Answer by CDNexus · Apr 15, 2017 at 04:25 AM
I am sure you have worked out a solution by now. However here is mine for anyone that is stuck on the same issue:
Edit Standard Assets\Characters\ThirdPersonCharacter\Scripts\ThirdPersonCharacter.cs
Add a call to a new method checkClimb() in public void Move(Vector3 move, bool crouch, bool jump):
...
else
{
HandleAirborneMovement();
}
checkClimb(); // <-- add this
ScaleCapsuleForCrouching(crouch);
...
Then create a method to handle vertical translations based on a ray check that happens from above in front of the character as they move:
/// <summary>
/// Work out Y Movement. We may need multiple checks here later too, to prevent us falling into small cracks.
/// </summary>
/// <param name="move"></param>
private void checkClimb()
{
float distanceDown = m_offsetVerticalForVerticalChecks + 2.5f;
//float stepOffsetVerticalForHorizontalChecks = 0.1f;
//float maxOffsetVerticalForHorizontalChecks = 1.5f;
RaycastHit hitInfo;
#if UNITY_EDITOR
// helper to visualise the climb check ray in the scene view
Debug.DrawLine(
transform.position + (Vector3.up * m_offsetVerticalForVerticalChecks) + (this.m_ForwardAmount * this.transform.forward * 0.5f),
transform.position + (Vector3.up * m_offsetVerticalForVerticalChecks) + (this.m_ForwardAmount * this.transform.forward * 0.5f) + (Vector3.up * (m_offsetVerticalForVerticalChecks - distanceDown)));
#endif
// Actually do the check
bool collided = Physics.Raycast(
transform.position + (Vector3.up * m_offsetVerticalForVerticalChecks) + (this.m_ForwardAmount * this.transform.forward * 0.5f),
Vector3.down,
out hitInfo,
distanceDown);
if (collided && m_offsetVerticalForVerticalChecks + m_maxVerticalFall > hitInfo.distance)
{
if ((m_offsetVerticalForVerticalChecks - hitInfo.distance <= m_maxVerticalClimb) && (m_offsetVerticalForVerticalChecks - hitInfo.distance > 0.0f))
{
this.transform.Translate(new Vector3(0.0f, m_offsetVerticalForVerticalChecks - hitInfo.distance, 0.0f));
}
}
}
Also note that this project setting to disable ray checks against triggers was necessary in my case. I am sure there is a way to prevent this check occurring against triggers in the code. Please reply if anyone does work that out.