Animated Mesh Character Controller

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Animated Mesh Character Controller

Postby KKlouzal » Tue Jan 23, 2018 2:37 pm

I'm planning to design a character controller that provides semi-accurate hitboxes for an animated mesh.

My idea is to create an extremely low-poly version of the actual character model and split it into pieces:
Head
Upper_Body
Lower_Body
Left_Foot/Right_Foot
Lower_Left_Leg/Lower_Right_Leg
Upper_Left_Leg/Upper_Right_Leg
Left_Hand/Right_Hand
Left_Forearm/Right_Forearm
Left_Upperarm/Right_Upperarm

Each frame after the player model is animated I will extract out the positions and rotations from each bone and apply them to the appropriate piece listed above. These pieces would only be used for ray-casts to check if for example a bullet hit a particular spot on the body.

Aside from these pieces I could use two capsule shapes for actually moving the character through the environment. One tall capsule to represent the standing character and one short capsule to represent the crouched player. Collisions would only ever be enabled on one capsule depending on the crouched state of the character.

To me this setup seems like it would provide the best performance since the "pieces" would only ever be used for ray-casts and the capsules are used for physical movement through the world.

The only thing that slightly bothers me with this is that if for example a box is thrown at a player then the collision would happen with the capsules and thus it wouldn't quite look right (especially if the character was bent down in a 'touching their toes' position).
This leads me to want to drop the capsules all together and use the pieces for movement as well however I feel that manually setting the positions and rotations on these objects during animation would be problematic for movement.

I'm not even sure I can safely set the physical positions and rotations of a physics body, I have a feeling I must manipulate them using forces/impulses?
Am I on the right track here or is there a better way to do this?
User avatar
KKlouzal
 
Posts: 16
Joined: Tue Jan 23, 2018 11:59 am

Re: Animated Mesh Character Controller

Postby JoeJ » Tue Jan 23, 2018 6:37 pm

KKlouzal wrote:I'm not even sure I can safely set the physical positions and rotations of a physics body, I have a feeling I must manipulate them using forces/impulses?
Am I on the right track here or is there a better way to do this?


There a are quite many options.

You can use kinetic bodies: You can set their position and also their velocity, and how they collide with dynamic bodies. E.g. you create a conveyor belt by setting velocity, but position does not change. In this matter you would have some control of how the character affects the enviroment. But a stone thrown to the character would not affect the character.
I'm very sure this approach allows a smooth simulation, and the manual setting of position can not mess up anything. (Sudden intersections get resolved slowly by Newton)

You can also use forces, calculated from the animation data to make physical bodies follow the animation. If those forces have max values and you add ragdoll joints to the bodies, the character would show some impact from the stone. (But then it would just continue to follow to the animation data, of course.)

Personally i made one more step and added motors to joints. The ragdoll can accurately play back animation data accurately. But there is no more external force that keeps it upright, so you can cheat and just add it, or move towards self balancing and walking ragdolls (which i achieved with current Newton, but took me years.)
Julio actually works on something in this direction...

It's also possible to mix up anything i've said. I assume there are no limitations in Newton that hinder you in anything you want to do. But the problem of what (procedural) animation you should use is up to you. (at least for now...)

You can also keep using capsules and make them collideable with ground, but not with the stones.
User avatar
JoeJ
 
Posts: 1453
Joined: Tue Dec 21, 2010 6:18 pm

Re: Animated Mesh Character Controller

Postby KKlouzal » Wed Jan 24, 2018 11:29 am

Okay that all sounds very good, thank you!

A self balancing bipedal controller would be extreme overkill and a waste of precious processing cycles for my needs.

I'll go ahead and use a capsule to move the character around in the simulation (or dual-capsules, one for standing and one for crouching, if I am unable to dynamically change the capsule shape at runtime).

Then I will effectively attach simple collision shapes to each bone of the character model and update their position/rotation based on each bones position/rotation every frame before stepping the simulation. This should allow other bodies in the simulation to more accurately react to the character model (instead of being pushed by the capsule they will be pushed by the bodies attached to the bones). Raycasts will also ignore the capsule and be tested against these physics bodies a to determine where on the character a bullet will collide.

I also have no need for the character to be directly effected by objects that collide with it. Objects thrown at the character should accurately bounce off the character, for this the capsule will not be accurate enough and the physics bodies must be used, otherwise it will appear as if objects mysteriously bounce off the character some small distance away from them (wherever the capsule is).

I don't believe there should be any need for joints/motors since I will be directly setting positions and rotations each frame.

This simple configuration should provide the best performance with plenty of accuracy.

I will go ahead and get started on this and share my results here when completed!
User avatar
KKlouzal
 
Posts: 16
Joined: Tue Jan 23, 2018 11:59 am

Re: Animated Mesh Character Controller

Postby JoeJ » Wed Jan 24, 2018 12:33 pm

Yeah, this should work as you intend. Some details:

To get realistic collision response, you do not only need to set position and orientation but also linear and angular velocities (which is easy to calculate from animation data or previous state), and also mass.

But the higher that velocity and mass is, the higher is the risk the simulation gets affected in a bad way. Think of superman weighting 10 tons running around - he would kick cars to heaven and push objects through walls just by getting in contact with them. So i would start with real life mass, but clamp velocities at a lowest possible max value.

I guess kinematic bodies are better suited than dynamic ones, but you can try both.

KKlouzal wrote:(or dual-capsules, one for standing and one for crouching, if I am unable to dynamically change the capsule shape at runtime).


Personally i use a dynamic capsule body with an up-vector joint to keep it upright and apply force to move it (calculated from target velocity). Using a maximum for the applied force, heavy dynamic obstacles slow the character down as he pushes them aside.

Other people prefer using a kinetic body: No need for up-vector joint, set velocity directly.
Newton character controller is an example for this i think. (I don't know how it behaves on obstacles and how this is configurable.)

I never tried to change the shape of a body at runtime, but i assume it would work. Using 2 bodies and moving the upper inside the lower when crouching would be an alternative.

You can also set velocity for dynamic bodies, which is easier to start. But it's not recommended (e.g. you accidently set velocity to move a body into a wall). So you can convert your velocities to force / torque later when you're happy. I did not get a noticeable lag or something from that.
User avatar
JoeJ
 
Posts: 1453
Joined: Tue Dec 21, 2010 6:18 pm


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 13 guests

cron