PuppetMaster Integration

Sergey Bespalov

New member
Hello. This is a little guide how to integrate UFPS 2 with PuppetMaster.
With PuppetMaster you can have enemies that reacts on hits more realistic (3mb gif):

Integration with PuppetMaster is easy. Little changes in Health.cs, ShootableWeapon.cs, HealthInspector.cs are needed

Health.cs
Add necessary import:

using RootMotion.Dynamics;

Add property m_PuppetMaster:

C#:
[SerializeField] protected bool m_PuppetMaster;
...
public bool IsPuppetMaster { get { return m_PuppetMaster; } set { m_PuppetMaster = value; } }

Add a parameter "Rigidbody hitBody" to method Damage:
C#:
public virtual void Damage(float amount, Vector3 position, Vector3 direction, float forceMagnitude, int frames, float radius, GameObject attacker, Collider hitCollider, Rigidbody hitBody)
Add method Damage:
C#:
public virtual void Damage(float amount, Vector3 position, Vector3 direction, float forceMagnitude, int frames, float radius, GameObject attacker, Collider hitCollider)
        {
            Damage(amount, position, direction, forceMagnitude, frames, radius, attacker, hitCollider, null);
        }

Changes in method Damage:
C#:
...           
                if (forceMagnitude > 0) {
                // Apply a force to the object.
                if (m_ForceObject != null) {
                    m_ForceObject.AddForce(force, frames);
                } else {

                    //Puppetmaster integration
                    if (m_PuppetMaster)
                    {
                        var broadcaster = hitBody.GetComponent<MuscleCollisionBroadcaster>();
                        if (broadcaster != null)
                        {
                            broadcaster.Hit(forceMagnitude, force * MathUtility.RigidbodyForceMultiplier, position);
                        }
                    }
                    // Apply a force to the rigidbody if the object isn't a character.
                    else if (m_Rigidbody != null && !m_Rigidbody.isKinematic) {
                        if (radius == 0) {
                            m_Rigidbody.AddForceAtPosition(force * MathUtility.RigidbodyForceMultiplier, position);
                        } else {
                            m_Rigidbody.AddExplosionForce(force.magnitude * MathUtility.RigidbodyForceMultiplier, position, radius);
                        }
                    }
                }
            }
...

HealthInspector.cs

Added string
EditorGUILayout.PropertyField(PropertyFromName("m_PuppetMaster"));
in method GetDrawCallback()

ShootableWeapon.cs

In HitscanFire(float strength) we should transfer rigidbody that was hit to Health (Added a rigidbody parameter to Health.Damage):
C#:
if ((hitHealth = hitGameObject.GetCachedParentComponent<Health>()) != null) {
    hitHealth.Damage(damageAmount, m_HitscanRaycastHits[i].point, fireDirection, m_ImpactForce * strength, m_ImpactForceFrames, 0, m_Character, m_HitscanRaycastHits[i].collider, m_HitscanRaycastHits[i].rigidbody);

Now if am enemy has Health.cs script and the checkbox "Puppet Master" active then you can use PuppetMaster for enemy animation.
*I did not test it with meele weapon and with grenades. I think there will be more work with grenades an melee.
Scripts are attached to the post
 

Attachments

  • Scripts.zip
    23.2 KB · Views: 25
Thanks a lot! I never used Puppet Master but I'll definitely check it out. I believe PM can do more than just hit-reaction. Have you tested other stuff? like falling over obstacles and such?

BTW, I'm very interested in FinalIK for various weapon handling. Have you tried FinalIK integration? I don't know enough about FinalIK and it seems to require more deep integration to make it work with UCC nicely.

I'm looking forward to use both FinalIK and PM in my game soon.

Cheers!
 
I have watched few videos about FinalIK but I have not had chance to try it and I don't understand what can I do with FinalIK. I have Umotion Pro that let me to create IK and use it for animations. What are features of FinalIK?
Falling over obstacles - it is easy and cool. Also with PuppetMaster you can remove parts of the body of enemy when it was hit, like in Dead Space (It was in PuppetMaster demo scene).
 
Ah, removing parts of a body is interesting...
FinalIK let you do runtime IK. It will let you do interactions with various objects, such as weapon handling, door interaction, and etc. They have a bunch of videos on their appstore page. Check it out if you haven't and I'm really excited about using them in my game.
Cheers!
 
Hi, thank you for taking the time to explain the script changes needed for integration between UFPS2 and PuppetMaster and posting them for us all. I've been waiting awhile for Partel over at RootMotion to complete an updated integration package so when I saw this I got excited.

I am having some problems however getting everything to work correctly. Spent a few hours last night trying different things and can't come up with a reliable setup. If you could possibly explain just a little further on how you exactly setup the character to work with puppet master I would greatly appreciate it.

First I'm trying to integrate with the UCC version and PuppetMaster; I do not own UFPS2 so I do not know if they are fundamentally different or we are talking about the same product sorry for confusion.

I am also confused on how to initially setup the character itself. Ive tried many different configurations but none work completely.

Do I create a ragdoll first through puppet master then go through character manager afterward to integrate the character controller etc? If so do I need to check the ragdoll box? Do I disable Unity IK? Any help on correct settings for initial setup is welcome thanks.

Also, are you strictly using just the Health.cs script on characters and not the rest of the controller?

Are you calling any specific On Death Events in Health.cs to tell puppet master anything?

Are you setting up the hitboxes from puppet master to the Health.cs script? Any additional info would be greatly appreciated.

Thanks!
 
Has anyone got PuppetMaster to integrate with UCC? Setting up was easy but I'm having a problem with recovery from the fall.
When gets up, it's trying to snap to the position before the fall. Instead, UCC position should move to the current Puppet position.
 
Top