Search Unity

Bug in unity firstperson Character Motor script. need help.

Discussion in 'Scripting' started by Harry64, Jul 28, 2013.

  1. Harry64

    Harry64

    Joined:
    Jan 21, 2013
    Posts:
    18
    Hello!

    I sit here how like 4 hours infront of my slightly modified Character Controller Script that comes with unity 4.

    I found out that there was a bug in the sliding settings so that even if you disabled the sliding in the inspector it was still aktive.

    I changed it now from
    if (grounded TooSteep()) {
    to
    if (sliding.enabled grounded TooSteep()) {

    now I can disable the sliding.

    but now I cant stop thinking about another bug that has to do with the sliding option.

    when I tryed to build stairs and I set the StepOffset to a high value even then the character controller was still not able to walk up the stairs. only if I run over the stairs with full speed. so I ended up to put just a collider block over the stairs.

    but now I found out when I disable the sliding of my character I can walk normally over the stairs. even little blocks on the floor wont bother me.
    and now the StepOffset works like intended. bevore I tryed it even with a high block and with very high StepOffset settings and my characterController plopped up to the top of the block and slided of at the same time...

    I found out that the function OnControllerColliderHit in this script may does something wrong but I am just a coding beginner and now its very late and I think I will not be able to solve this problem alone.
    but I want that the player is able to slide of stuff and walls. but I also want to understand what is wrong here.


    what I found out is that when I walk to a step of a stair the hit.normal and the lastGroundNormal from the code down here maybe recognize the 90° side of the step and because of that the charactercontroller starts to slide of till the controller is back on the floor.
    even if the StepOffset is set high enough the player plopps up and even stand already on the stair but then the character controller is pulled back.


    Code (csharp):
    1. public function OnControllerColliderHit (hit : ControllerColliderHit)
    2. {
    3.     var velocity : Vector3 = movement.velocity;
    4.    
    5.     if (hit.normal.y > 0  hit.normal.y > groundNormal.y  hit.moveDirection.y < 0)
    6.     {
    7.         if ((hit.point - movement.lastHitPoint).sqrMagnitude > 0.001 || lastGroundNormal == Vector3.zero)
    8.             groundNormal = hit.normal;
    9.         else
    10.             groundNormal = lastGroundNormal;
    11.        
    12.         movingPlatform.hitPlatform = hit.collider.transform;
    13.         movement.hitPoint = hit.point;
    14.         movement.frameVelocity = Vector3.zero;
    15.     }
    16.  
    when I change the line groundNormal = lastGroundNormal to groundNormal = hit.normal;
    then the characterController stops sliding down from 1 steps. but if its a full stair he wont be able to go up one step.