Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2004
    Location
    United Kingdom (South)
    Posts
    991

    Not Dying and Dying when not supposed to.

    I have watched / coded through the TPCharacter videos (all sets) but I have an odd problem. My character will not die if it jumps from a height that should kill it. If I walk off of an edge at the same height it kills me. After I respawn I then die automatically if I jump (even if jumping on the spot!). If I then walk off at a height at which I wouldn't die I don't die and from that point jumping off of tall objects fails to kill me again.

    I've been looking and figure it must have something to do with the code I have for the Jump. I still have a comment in the else statement at the end of Jumping() in TP_Animator so I wonder whether this has something to do with the problem. Really though I am tired and can't think about it properly. Maybe I'll figure it out tomorrow but I've been looking and trying to locate the problem for a good couple of hours now.

    It seems like after a reset when trying to jump the character goes straight from idle to landing then to dead.
    Last edited by Avace; 03-21-2011 at 04:51 PM. Reason: Attempt to correct title spelling!

  2. #2
    Join Date
    Dec 2002
    Location
    Virginia Beach, VA
    Posts
    861
    Sounds like your not reseting all the states correctly after dieing.

  3. #3
    Join Date
    Jun 2010
    Posts
    24
    It could be something wrong in your code for Falling, not reseting the VerticalVelocity after jumping.
    If you could post your code, it will help .
    Meanwhile check if you have the same code here :

    Code:
    // TP_MOTOR
    // Properties
    public bool IsFalling
        {
            get { return isFalling; }
            set 
            {
                isFalling = value;
    
                if (isFalling)
                {
                    startFallHeight = transform.position.y;
                }
                else
                {
                    if (startFallHeight - transform.position.y > FatalFallHeight)
                        TP_Controller.Instance.Die();
                }
            }
        }
    
    
    //Methods
    void ApplyGravity()
        {
            if (MoveVector.y > -TerminalVelocity)
                MoveVector = new Vector3(MoveVector.x, MoveVector.y - Gravity * Time.deltaTime, MoveVector.z);
    
            if (TP_Controller.CharacterController.isGrounded && MoveVector.y < -1)
            {
                MoveVector = new Vector3(MoveVector.x, -1, MoveVector.z);
            }
        }
    Code:
    //TP_ANIMATOR
    
     public void Fall()
        {
            if (TP_Motor.Instance.VerticalVelocity > -5 || IsDead)
                return;
            lastState = State;
            State = CharacterState.Falling;
    
            TP_Motor.Instance.IsFalling = true;
            animation.CrossFade("Falling");
        }
    I hope it helps =)

  4. #4
    Join Date
    Feb 2004
    Location
    United Kingdom (South)
    Posts
    991
    Thanks for the suggestions . I'm a step closer to my answer now as I've eliminated not dying from jumping as an issue. The surface I was jumping from was high enough for me to run off and die but not high enough to jump off and die as the fall starts at a later stage due to the jump. My issue now is that jump causes me to die irrespective of fall height after my first death. When I land again without jumping it is seems to reset it.

    I've now added the following lines in my Reset method to reset the startFallHeight. This is a bit of a workaround though...

    Code:
            TP_Motor.Instance.IsFalling = true;
            TP_Motor.Instance.IsFalling = false;
    I've ditched the above as I have more of an idea of the issue.

    It seems that the problem is that startFallHeight is not reset at any point so we have a situation where the character can land successfully. So when we jump and land, IsFalling is set to false again and the startFallHeight has not changed and still evaluates
    Code:
    if (startFallHeight - transform.position.y > FatalFallHeight)
    to true causing the character to die.

    We know that we've landed when we're setting isFalling to false so I've reset startFallHeight after calling Die():

    Code:
        public bool IsFalling
        {
            get { return isFalling; }
            set 
            {
                isFalling = value;
                if (isFalling)
                {
                    startFallHeight = transform.position.y;
                }
                else
                {
                        if (startFallHeight - transform.position.y > FatalFallHeight)
                        {
                            TP_Controller.Instance.Die();
                            startFallHeight = transform.position.y;
                        }
                }
            }
        }
    I expect this would have been noticed in testing so it would seem that I've missed something in the videos somewhere.
    Last edited by Avace; 03-21-2011 at 04:52 PM. Reason: add solution

Posting Permissions

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