Search Unity

AnimFollow active ragdoll is now free to download.

Discussion in 'Assets and Asset Store' started by Kavorka, Jan 4, 2014.

  1. Kavorka

    Kavorka

    Joined:
    Sep 15, 2012
    Posts:
    247
    - Master jumps, slave follows.
    - Yes.
     
  2. shubhro

    shubhro

    Joined:
    Feb 5, 2022
    Posts:
    12
    Isn't Adding rigid body to the master will mess up the whole ragdoll balance? For example when the ragdoll is getting up.
     
  3. Kavorka

    Kavorka

    Joined:
    Sep 15, 2012
    Posts:
    247
    Oh, you are trying to make it jump. I thought that there was a jump. I had a jump, did I take it out? Haven't touched AnimFollow in years.
    I don't remember how I made it jump. I know I did not use rigidbody.addForce on the master. Don't add a rigid body to the master. Try jumping the master by just moving it by its transform. You have to calculate the transform.position by the physics equation for a ballistic body. I am sure there are a jump tutorial somewhere. Make a variable for vx and vy and set them to something when you jump. Then update transfom.position.y += vy*dt, vy -= 9.82*dt and transfom.position.x += vx*dt. Assuming y is up in Unity.

    Don't do any physics on the slave, I think that take care of itself, maybe.
     
  4. shubhro

    shubhro

    Joined:
    Feb 5, 2022
    Posts:
    12
    Thank you for replying. I am trying to get this result from page 1:

    I have tried the above method, but i think changes are also need to be done in SimpleFootIK script.
    I have added this code in PlayerMovement:

    Code (CSharp):
    1.  private void Update()
    2.         {
    3.             if (Input.GetButtonDown("Jump"))
    4.             {
    5.                 simpleFootIK.followTerrain = false;
    6.                 Jump();
    7.             }
    8.  
    9.             // calculate the new position according to jump
    10.             float deltaTime = Time.deltaTime;
    11.             Vector3 currentPosition = transform.position;
    12.             float verticalDisplacement = verticalVelocity * deltaTime - 0.5f * gravity * deltaTime * deltaTime;
    13.             Vector3 newPosition = new Vector3(currentPosition.x, currentPosition.y + verticalDisplacement, currentPosition.z);
    14.             transform.position = newPosition;
    15.  
    16.             if (simpleFootIK.followTerrain == false)
    17.             {
    18.                 verticalVelocity -= gravity * deltaTime;
    19.             }
    20.         }
    21.  
    22.         private void Jump()
    23.         {
    24.             verticalVelocity = jumpForce;
    25.         }
    I am disabling the followTerrain (in SimpleFootIK) because without that i was unable to move the master.
    This is not working for me. After jump, the ragdoll is unable to getup when hitting the ground (i think the master is unable to go back to ragdoll's position)
     
  5. Kavorka

    Kavorka

    Joined:
    Sep 15, 2012
    Posts:
    247
    Don't remember what I did to the simple foot IK and still hoping you will solve this yourself so I don't open Unity until necessary. Apologies for being a lazy ( and busy ) prick :) You seem to have found some stuff out yourself, good work.

    Doesn't the code you wrote run every frame, even after you land? If it does you are overriding the masters transform and breaking everything. You need a "grounded" bool such that your code only overrides the transform when you are in the air.
     
    shubhro likes this.
  6. shubhro

    shubhro

    Joined:
    Feb 5, 2022
    Posts:
    12
    Thanks for the tip and keeping the conversation going.
    I have managed to make the jump work just like in your video. I don't know how right or wrong it is.
    Here is the updated code:

    Code (CSharp):
    1. private void Update()
    2.         {
    3.             if (Input.GetButtonDown("Jump") && readyToJump)
    4.             {
    5.                 simpleFootIK.followTerrain = false;
    6.                 readyToJump = false;
    7.                 Jump();
    8.             }
    9.  
    10.             // calculate the new position according to jump
    11.             //Debug.DrawRay(transform.position, Vector3.down * isGroundRayLength, grounded ? Color.green : Color.red);
    12.             if (simpleFootIK.followTerrain == false && !readyToJump)
    13.             {
    14.                 float deltaTime = Time.deltaTime;
    15.                 Vector3 currentPosition = transform.position;
    16.                 float verticalDisplacement = verticalVelocity * deltaTime - 0.5f * gravity * deltaTime * deltaTime;
    17.                 Vector3 newPosition = new Vector3(currentPosition.x, currentPosition.y + verticalDisplacement, currentPosition.z);
    18.                 transform.position = newPosition;
    19.  
    20.                 verticalVelocity -= gravity * deltaTime;
    21.  
    22.                 grounded = Physics.Raycast(transform.position, Vector3.down, isGroundRayLength);
    23.  
    24.                 if (!grounded) inAir = true;
    25.  
    26.                 if (grounded && !readyToJump && inAir) // player was in air before | cannot jump until hit the ground | is now grounded
    27.                 {
    28.                     simpleFootIK.followTerrain = true;
    29.                     readyToJump = true;
    30.                     inAir = false;
    31.                 }
    32.             }
    33.  
    34.         }
    35.  
    36.         private void Jump()
    37.         {
    38.             verticalVelocity = jumpForce;
    39.         }
     
  7. Kavorka

    Kavorka

    Joined:
    Sep 15, 2012
    Posts:
    247
    Great, you made it.
    Don't need this " - 0.5f * gravity * deltaTime * deltaTime".
     
    shubhro likes this.
  8. shubhro

    shubhro

    Joined:
    Feb 5, 2022
    Posts:
    12
    Hi there!
    I am unable to understand what parameters or properties are causing this.
    When the player falls down, such as from a higher platform to a lower one, it hits the ground with significant speed. When using the above script to initiate a jump, I have control over the descent speed (fall). However, once I relinquish control to the ragdoll, it abruptly crashes to the ground.
     

    Attached Files:

  9. Kavorka

    Kavorka

    Joined:
    Sep 15, 2012
    Posts:
    247
    Don't know either, but since there is no jump there is likely no "fall by gravity", only followTerrain, and you magically made the terrain 20 meters lower in one frame so the followTerrain does its best to follow. Maybe, idk. You could make your grounded bool detect that you are in the air and build a fall by gravity system.