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:
Add property m_PuppetMaster:
Add a parameter "Rigidbody hitBody" to method Damage:
Add method Damage:
Changes in method Damage:
HealthInspector.cs
Added string
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):
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
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)
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