Puppetmaster impact registration

WillyG99

Member
Hi, i've tried to integrate puppetmaster with behaviour tree and UFPS, which has been working great so far, but i want to register an impact from puppetmaster when i hit a target with my projectile from "Shootable Weapon". I tried using physcial projectiles, but the speed of the projectiles ignore the impact, sadly.

I hope it's ok that i post the puppetmaster code, which is a raycast that applies force and "unpin" which makes the character/victim flinched and more wobbly from the impacts which will eventually make the character fall over. I've spent the whole day trying to integrate it myself, but can't do it, i'm very inexperienced with coding.

Code:
  1. using UnityEngine;
  2. using System.Collections;
  3. using RootMotion.Dynamics;

  4. namespace RootMotion.Demos {

  5. public class RaycastShooter : MonoBehaviour {

  6. public LayerMask layers;
  7. public float unpin = 10f;
  8. public float force = 10f;

  9. // Update is called once per frame
  10. void Update () {
  11. if (Input.GetMouseButtonDown(0)) {
  12. Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

  13. // Raycast to find a ragdoll collider
  14. RaycastHit hit = new RaycastHit();
  15. if (Physics.Raycast(ray, out hit, 100f, layers)) {
  16. var broadcaster = hit.collider.attachedRigidbody.GetComponent<MuscleCollisionBroadcaster>();

  17. if (broadcaster != null) {
  18. broadcaster.Hit(unpin, ray.direction * force, hit.point);
  19. }
  20. }
  21. }
  22. }
  23. }
  24. }

As of now this code does all that by clicking on a "puppet character", but i want to apply the same functions when my projectile hits the enemy.



Hope it's ok i ask this here
 
Yeah i've tried to do it with the impact event but not sure how, i want to atleast use the unpin float to "unpin" the limb that has been hit, but not sure how to call that on impact.
The force will be dealt with by UFPS, so i just need the unpin i believe
 
I'm not familiar with Puppetmaster so I can't comment on that side of things. The Projectile component executes the "OnImpact" event when it collides with an object, so you could listen to that event to execute any other code you need. An explanation and example script of this is on this page, under the "Impact Callback" header: https://opsive.com/support/document...troller/objects/trajectory-object/projectile/
Is there a way i could call that raycast script above when my gun is firing somehow?
 
You could register every muscle in puppetmaster for the OnImpactEvent (looping through the muscle array in awake). You get force direction and amount, which you can use in the function from the raycast shooter script.
 
You could register every muscle in puppetmaster for the OnImpactEvent (looping through the muscle array in awake). You get force direction and amount, which you can use in the function from the raycast shooter script.
You mean using the Event system for the projectile in the inspector? I'm not sure if i can, the puppetmaster character and projectile are both prefabs, or do you mean coding it in manually? Because if so then i'm not sure how, i think i'll start taking some classes in coding because i feel so helpless without it.
 
Is there a way i could call that raycast script above when my gun is firing somehow?
You could use the OnItemStartUse event I suppose, but I feel like you'd want this to happen when a projectile actually collides with an object, no?

You mean using the Event system for the projectile in the inspector? I'm not sure if i can, the puppetmaster character and projectile are both prefabs, or do you mean coding it in manually? Because if so then i'm not sure how, i think i'll start taking some classes in coding because i feel so helpless without it.
Yeah sounds like you'd need to add a custom script to the character prefab and register to the OnImpactEvent as Klin suggested.
 
You mean using the Event system for the projectile in the inspector? I'm not sure if i can, the puppetmaster character and projectile are both prefabs, or do you mean coding it in manually? Because if so then i'm not sure how, i think i'll start taking some classes in coding because i feel so helpless
If your coding knowledge is absolutely zero, unfortunately this won't help you.
But since you ask, I'd personally recommend learning it so you don't have to rely solely on what assets offer you. Especially if you want to combine different asset features (like what you meantioned).
 
Yes, i'm trying to learn the new Unity visual scripts, they should be ok to combine with regular scripts to an extent, maybe i can work with that, if not i'll try to do a custom script like suggested, i'm sure i'll figure it out at some point.
Thank you both for the help ?
 
Top