Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Physics-based Animation System for Characters

Discussion in 'Physics' started by dimitur_kolev2, Jan 17, 2017.

  1. dimitur_kolev2

    dimitur_kolev2

    Joined:
    Nov 2, 2015
    Posts:
    4
    Currently im working on a PB animation system and I made some progress but....Its hard and there isnt anything much on the internet.
    Basically I setup the ragdoll and then apply a constant force on the head or hips to thurst upwards,to keep the ragdoll straight.
    Now comes the hard part : walking.
    I've managed to create a semi-working walking cycle by doing 2 functions attached to each leg with thursters and them using them with coroutines.The first problem is that i cant find a way to make a perfect interval based loop so that each leg waits for the other to move and then to move.
    The second problem is that i cant actually figure out a way to make him look like he is properly stepping.
    Any info on this dark magic subject would be a blessing guys!
    Thank you and have a good day!
     
    AntonioModer likes this.
  2. Nubnubbud

    Nubnubbud

    Joined:
    Nov 19, 2014
    Posts:
    10
    when doing things based on physics, it's best to think how it works in physics. real people are supported by their feet, not a floating head. I'm no expert coder, but supporting the character from the bottom up, starting with the feet, seems like the way to go. I would try this:
    • feet stay always against the ground if both: the foot is close enough to the ground and the ankle is bent less than 45 degrees (average flexibility). (you can make the ball of the foot count as grounded too, and after the ankle can bend no more, bend the ball of the foot 45 degrees to allow for crouching)
    • Hips carry the center of mass, and must remain above the heels, or leaning off balance in the direction of movement. Remember, running and walking are not pushing with our feet, they are falling, then catching and pushing ourselves back up with each step
    • The upper body angles forward with the hips, arm motion opposing leg motion for balance. this requires good foot friction to work
    • Knees apply a force from the ankles toward the hips by straightening the two halves of the legs. this is a soft constraint and like a hinge spring when tensed. also notice that if previously moving forward, because the motion is toward the hip, the legs push the hip a a little forward, as well as up.
    • in order to move, the hips bend the torso forward. to strafe, one knee relaxes a bit, letting the other push off, and the relaxed leg catches the fall. All movement is falling, with the feet moving to catch it.
    • if a foot is not able to reach the ground from an ankle, it is not supported, the knee tenses some, and the leg moves in the direction the hips are leaning off balance.the leg extends, and the foot nears the ground to make a grounded connection.
    to get the walking gait down correctly, note leaning is only the beginning of walking, the rest is just putting a foot ahead, and allowing the lateral motion to continue.
     
    Last edited: Jan 18, 2017
  3. dimitur_kolev2

    dimitur_kolev2

    Joined:
    Nov 2, 2015
    Posts:
    4
    Thanks for the extensive response!
    Im pretty much a newbie with c# so these things will take quite some time to implement.
    I know this is a pretty serious topic , but the effect Im trying to achieve is rather comical,like gangbeasts,octodad
    and so on.Thanks again!
     
  4. Nubnubbud

    Nubnubbud

    Joined:
    Nov 19, 2014
    Posts:
    10
    ah, okay, I know gang beasts has the head held up to just under the standing height, with a soft constraint so the foot animation would lift it up. there's definitely some interesting stuff under the hood there that I can't quite figure out.
     
  5. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    23,350
    The problem with this is you would likely not want physics but IK, because physically doing this is going to fall apart due to a lack of iterations, or be really quite slow to calculate.
     
  6. Nubnubbud

    Nubnubbud

    Joined:
    Nov 19, 2014
    Posts:
    10
    ah, I hadn't considered that, but that really does seem like the way to go. My only venture into the area was considering the plausibility of a cheap peripheral to apply resistance to the player's joints from resistances in-game, so I kinda glossed over procedural movement =3=
     
  7. raithza

    raithza

    Joined:
    Dec 14, 2011
    Posts:
    13
    I think I'm doing exactly what you're after in my game GORN. Don't overcomplicate it. Keep the character upright by applying an upwards force on the chest. Keep the chest straightened by using two addforceatposition - an upwards one at the top, and a downwards one at the bottom. Think of the character as a puppet on strings, each force that you are applying is another string - so to straighten something you attach a string to the top and at the bottom and you pull on both of them equally.

    A walk cycle is a simple up, then forward, then down force applied to each foot, step by step. You can just apply a forward force to the chest if the foot forces aren't propagating him forward enough. A more advanced and stable way is to have a position relative to the chest/ground that each foot is following. Apply a downward force to the static foot so it stays on the ground.

    There's no shortcut to doing this, it takes a lot of tweaking. I later wound up adding rotational forces to the knee and hip at the start of a step to make the lift portion look more natural.

    Demo of a walk cycle done in this way:

    I'm also changing the desired height of the chest over the course of a step for a more natural up/down feel. the lines coming out the feet show (some) of the forces being applied.
     
    eobet and dimitur_kolev2 like this.
  8. Fleech

    Fleech

    Joined:
    Jan 9, 2017
    Posts:
    14
    i'm working on something like this as well.



    https://gfycat.com/SandyEdibleBoaconstrictor

    basically it all boils down to how far you want to take the simulation regarding how the characters move and balance. something like sumo tori with simulated weight transfer and attempted self balancing with no rotation locking, or something like exanima which has an IK hybrid system. right now i'm trying to find a nice middle ground between sumo tori and exanima.
     
    dimitur_kolev2 likes this.
  9. raithza

    raithza

    Joined:
    Dec 14, 2011
    Posts:
    13
    damn that looks seriously awesome!
     
    dimitur_kolev2 likes this.
  10. punkouter2018

    punkouter2018

    Joined:
    Jul 28, 2013
    Posts:
    170
    Ill pay a $1000 if anyone ever comes up with a Euphoria-like asset.
     
    dimitur_kolev2 and looki666 like this.
  11. dimitur_kolev2

    dimitur_kolev2

    Joined:
    Nov 2, 2015
    Posts:
    4
    Thank you for the extensive response and for the useful advices! I think ive seen you on some youtube series on an island! Great work!
     
  12. jeffweber

    jeffweber

    Joined:
    Dec 17, 2009
    Posts:
    504
  13. eobet

    eobet

    Joined:
    May 2, 2014
    Posts:
    155
    Last edited: May 14, 2018
  14. FuzzyShan

    FuzzyShan

    Joined:
    Jul 30, 2012
    Posts:
    165
    gangbeast uses a ball and prismatic joint when walking, it apply force downward on the ball, so the ball will have full friction against floor, then just do rotation for the ball depend on your input axis. When not walking, ball goes back to the "core body part" and collision is ignored against all body parts, both leg will then stand on the floor straight with a tightening effect to keep the body straight. alot of these described above will have to be simplified if you want to run on server simulation with client prediction.(Collision can happen for all other body parts, just make sure you ignore against "BALL"), I did this for following game: https://www.taptap.com/app/81133
     
    Last edited: May 31, 2018
    GameDevCouple_I and hippocoder like this.
  15. eobet

    eobet

    Joined:
    May 2, 2014
    Posts:
    155
    Collision with all body parts is something I personally definitely need.

    Found another tutorial:



    (Yes, spanish, but worth it, I think... and he's got a whole series of these if you check his channel.)
     
  16. rallymoose

    rallymoose

    Joined:
    Apr 22, 2018
    Posts:
    1
    I wonder about another thing... would it be possible too use a dynamic mesh collider to achive full body physics?
    And how would you add the data from a static mesh collider to a dynamic one...
    Thinking of using skeletion too restrict body movment....

    Hopfully if that works, use AI too figure out how too do the animation sequence and then have that replace the animation...
    AI in mind (TensorFlow).

    So too summarize,
    Idea: Use dynamic mesh collider too create the physics then use ai too learn the movement from an animation (or many) and then figure out animations on its own after a bit (or very much) training of the AI.

    Hope someone might have an idea on how too achieve the dynamic mesh collider and maybe the skeleton (body part) movement restriction.
     
  17. SparrowsNest

    SparrowsNest

    Joined:
    Apr 6, 2017
    Posts:
    370
    I haven't had time to read all the comments, but I agree with this.
    As far as I know all game do this instead of trying to simulate actual muscles.

    You should think about it more like puppeteering the character.