Page 1 of 3 123 LastLast
Results 1 to 10 of 23

Thread: Sliding error

  1. #1
    Join Date
    Jul 2005
    Location
    Scotland
    Posts
    962

    Sliding error

    Hi Guys,

    I appear to be having an issue with the sliding functionality in the character controller, I noticed after I finished up with the animator videos that the camera appeared to be shuddering when the velocity was increased and I've tracked it down to the ApplySlide method.

    I inserted a debug log line to appear when the character is sliding and not sliding and even though the character is moving along the floor it occasionally jumps between sliding and not sliding

    Code:
    void ApplySlide()
        {
            if (!TP_Controller.CharacterController.isGrounded)
                return;
            
            slideDirection = Vector3.zero;
    
            
            RaycastHit hitInfo;
    
            if (Physics.Raycast(transform.position + Vector3.up, Vector3.down, out hitInfo))
            {
    
                //Debug.Log(hitInfo.normal.y.ToString());
                if (hitInfo.normal.y < SlideThreshold)
                    slideDirection = new Vector3(hitInfo.normal.x, -hitInfo.normal.y, hitInfo.normal.z);
            }
    
            if (slideDirection.magnitude < MaxControllableSlideMagnitude)
            {
    
                Debug.Log("not sliding");
                MoveVector += slideDirection;
            }
            else
            {
    
                Debug.Log("In slide");
                MoveVector = slideDirection;
            }
        }
    When I comment out the call to ApplySlide() the shudder disappears

    Any help thoughts on what could be causing this issue would gratefully be appreciated
    Last edited by fatgav; 02-20-2011 at 05:23 PM. Reason: replaced quotation with code tags!

  2. #2
    Join Date
    Feb 2011
    Location
    Brisbane, Australia
    Posts
    71
    Stewart,

    A few people have had an issue when they create their character using a Unity capsule. Are you using a unity capsule ? If so, the pivot point for the Unity capsule is not on the ground so this line here:

    Code:
    if (Physics.Raycast(transform.position + Vector3.up, Vector3.down, out hitInfo))
    Should change to:

    Code:
    if (Physics.Raycast(transform.position, Vector3.down, out hitInfo))
    because the Raycast is probably hitting the top of your character.

  3. #3
    Join Date
    Jul 2005
    Location
    Scotland
    Posts
    962
    Thanks Crispie,

    Almost there now, When I removed the addition of the vector 3.up I'm in a sliding condition and thus can't move if I change the + vector3.up to -Vector3.up
    Code:
    if (Physics.Raycast(transform.position - Vector3.up, Vector3.down, out hitInfo))
    I can move around the level but cannot slide I appear to be stuck on the object even if I'm on top of the box on a flat surface I'm still in a sliding condition

    Atleast the camera shudder issue has been resolved

  4. #4
    Join Date
    Feb 2011
    Location
    Brisbane, Australia
    Posts
    71
    Don't change the operand, remove the Vector.up modification to the transform position.

  5. #5
    Join Date
    Jul 2005
    Location
    Scotland
    Posts
    962
    If I remove the operand vector3.up, the player does not move it's in a sliding condition
    Code:
    if (Physics.Raycast(transform.position, Vector3.down, out hitInfo))  // player does not move
    the slideDirection magnitude has a value of 1.

    The only way I can move using the suggested condintional statement is to jump.

    I do appreciate your assistance

  6. #6
    Join Date
    Feb 2011
    Location
    Brisbane, Australia
    Posts
    71
    Stewart,

    You need to start debugging what is actually being raycast and where it is raycasting from. Enter in the following to get a debug out and see if your getting the correct result.

    Code:
    Debug.Log("Hit Normal: " + hitInfo.normal.x + ", " + hitInfo.normal.y + ", " + hitInfo.normal.z + ". Hit Point: " + hitInfo.point.x + ", " + hitInfo.point.y + ", " + hitInfo.point.z + ". Distance: " + hitInfo.distance)
    That should (I think) give you the normal of the item being hit, where in world space it's colliding and the distance it traveled. It should show you how far the ray is travelling.

  7. #7
    Join Date
    Jul 2005
    Location
    Scotland
    Posts
    962
    Crispie,

    I'm at work just now but I'm planning going home for lunch, I'll add that dubug command and report back the results,

    Many Thanks.

  8. #8
    Join Date
    Feb 2011
    Location
    Brisbane, Australia
    Posts
    71
    No Problem. Sleepy time here (In Australia) but check the results. You should be able to work out if the ray is hitting the top of your character or the ground by the distance traveled and the normal returned.

  9. #9
    Join Date
    Jul 2005
    Location
    Scotland
    Posts
    962
    After the hitInfo is calculated
    Hit Normal: 0, -1, 3.029463E-07. Hit Point: -0.1116695, 1.786514E-09, 0.005897132. Distance: 0.915
    Now to check the documentation to find out what this all means

  10. #10
    Join Date
    Feb 2011
    Location
    Brisbane, Australia
    Posts
    71
    Hey Stewart, it basically means that the ray is intersecting with something at -0.1, 1.78, 0 (roughly). I assume you character is close to 1.78 tall ? Add this debug log to find out what the position you are casting from and see if it is the same as your character:

    Code:
    Debug.Log("Transform Position: " + transform.position + " Char Control Position:" + TP_Controller.CharacterController.transform.position);
    This should give you some idea at least from where you are starting your raycast and where your char controller is. I must say from the log though, and assuming your ground is at 0 on the Y axis, it is hitting something before the ground.

Page 1 of 3 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •