Search Unity

Wall Jump turn transition

Discussion in 'Animation' started by Siro13, Oct 14, 2020.

  1. Siro13

    Siro13

    Joined:
    Jun 30, 2014
    Posts:
    33
    Hi,
    I'm stuck on a transition problem between jumping off the wall and changing the direction of the character.

    I try to explain better:
    when I jump on the wall, I activate the animation as in the image Wall_grab.png.
    At this moment the capsule collider is turned to the left and through a box collider I check that I am in contact with the wall.
    When I press the space key, the animation of jumping off the wall starts and I turn the character to the other side then (right).
    At that moment, for a fraction of time, the character ends up inside the wall and then continues with the transition of the jump as in the image Wall_grab_turn.png and wall_grab_jump_transition.png. In the image you can see that the capsule collider and the box collider are turned to the right.

    Is there a way to make the character jump and turn, while jumping off the wall, without letting him go inside the wall?
    I thought about making the character change direction after a few milliseconds, but it doesn't work because it stays in an unnatural position in the air and then does all the animation.

    The same thing happens if I decide to change direction while the character is running. I have seen that there are transition animations of this type, but I have not understood how to manage the change of direction of the character smoothly without realizing that I am going from -X to + X.

    I hope I have clarified my problem and that someone can help me.
     

    Attached Files:

  2. Nathanieljla

    Nathanieljla

    Joined:
    Apr 18, 2014
    Posts:
    97
    Here's are my thoughts. Take a look at this image:
    bodyOrientation.png
    Imagine the left image is the character against the wall. The blue arrow is the direction of travel, the red arrow if the body orientation. In my animator I have an input called "heading offset" which tells me the direction the character should be offset from the blue arrow.

    If you're flipping your heading on a single frame (right image) I would find the angle different between previous direction and new direction (I'm assuming the wall normal) and set a private var called headingOffset to that angle. Then in future frames I would have that value transition back to zero.

    I would setup a blend tree that blends between those animations based on the heading offset. You'll flip on a frame, but not see the visual pop, because the character body flips as well.
     
  3. Siro13

    Siro13

    Joined:
    Jun 30, 2014
    Posts:
    33
    Thank you for your answer.
    I need to think a bit about your suggestion, but do you have an example (even a video) showing that operation?
     
  4. Nathanieljla

    Nathanieljla

    Joined:
    Apr 18, 2014
    Posts:
    97
    I actually just setup wall jumping in my code, but haven't setup the animations yet. Unfortunately I'm booked through this weekend, but could put something together on Monday.
     
  5. Nathanieljla

    Nathanieljla

    Joined:
    Apr 18, 2014
    Posts:
    97
    wallAnimExample.jpg
    Click on this thumbnail. This is roughly how I'd set this up. There's room for improvement. I measure the angle difference between the character forward direction and the wall. I currently do this with a heading value of 0-360, but doing 0-180 and 0- negative180 might make more sense. If it's 0-180 then the wall is to the right, if it's 0- negative 180 then the wall is to his left. I then feed this heading offset into an animator param to drive a 1D blend tree. You can then have different blend trees for wall left and wall right.

    Motor.CharacterUp won't be valid unless you are using the Kinematic Character Controller package, so you'll need to determine you're own up vec.

    Code (CSharp):
    1.  
    2.         private float GetHeadingOffset(Vector3 heading, bool threeSixty = true)
    3.         {
    4.             heading = Vector3.ProjectOnPlane(heading, Motor.CharacterUp);
    5.             heading = transform.InverseTransformDirection(heading);          
    6.             float offset = Mathf.Atan2(heading.x, heading.z) * Mathf.Rad2Deg;
    7.  
    8.             if (threeSixty && offset < 0)
    9.             {
    10.                 offset += 360f;
    11.             }
    12.  
    13.             return offset;
    14.         }
    15.  
    16.  
    17.         public float GetWallHeadingOffset()
    18.         {
    19.             float offset = 0f;
    20.             if (_wallJumpNormal.sqrMagnitude > 0.01f)
    21.             {
    22.                 offset = GetHeadingOffset( -_wallJumpNormal );
    23.             }
    24.  
    25.             return offset;
    26.         }
     
  6. Siro13

    Siro13

    Joined:
    Jun 30, 2014
    Posts:
    33
    Thanks Nathanieljla!

    In the Blend tree I see you have an animation for each rotation condition, am I right? then you use the correct animation based on the offset you calculate using the wall as a reference.
     
  7. Nathanieljla

    Nathanieljla

    Joined:
    Apr 18, 2014
    Posts:
    97
    Correct. Technically I don't think you need all 4, but I believe having only 180 might cause the rotation of the character to not go in the direction you want since the quaternion interpolation will go the shortest path. So you could do something like 120 and 240, but cardinal directions is common and it's fast enough to export.