public override void ApplyAnim(string anim, SkRuntimeInfo info)
 {
     base.ApplyAnim(anim, info);
     if (anim == "Knock")
     {
         SkInst inst = info as SkInst;
         if (inst != null)
         {
             if (m_View != null && inst._colInfo != null && inst._colInfo.hitTrans != null && inst._colInfo.hitTrans.GetComponent <Rigidbody>() != null)
             {
                 //Vector3 direction = inst._colTarget.transform.position - inst._colCaster.transform.position;
                 RagdollHitInfo hitInfo = PETools.PE.CapsuleHitToRagdollHit(inst._colInfo);
                 if (m_View is BiologyViewCmpt)
                 {
                     (m_View as BiologyViewCmpt).ActivateRagdoll(hitInfo, true);
                 }
             }
         }
         else
         {
             Debug.LogError("[ApplyAnim] Unsupported SkRuntimeInfo type");
         }
     }
     else
     {
         if (m_Animator != null)
         {
             m_Animator.SetTrigger(anim);
         }
     }
 }
Beispiel #2
0
        public override void DoAction(PEActionParam para = null)
        {
            if (null == viewCmpt)
            {
                return;
            }
            motionMgr.SetMaskState(PEActionMask.Wentfly, true);

            PEActionParamVFNS paramVFNS = para as PEActionParamVFNS;

            Vector3 force = paramVFNS.vec * paramVFNS.f;

            PeEntity entity = EntityMgr.Instance.Get(paramVFNS.n);

            motionMgr.FreezePhyState(GetType(), true);

            if (null != entity)
            {
                Transform hitColTran = entity.biologyViewCmpt.GetRagdollTransform(paramVFNS.str);
                if (null != hitColTran)
                {
                    RagdollHitInfo hitInfo = new RagdollHitInfo();
                    hitInfo.hitTransform = hitColTran;
                    hitInfo.hitPoint     = hitColTran.position;
                    hitInfo.hitForce     = force;
                    hitInfo.hitNormal    = -force.normalized;
                    viewCmpt.ActivateRagdoll(hitInfo, false);
                }
            }
            if (null != phyCtrl)
            {
                phyCtrl.desiredMovementDirection = Vector3.zero;
                phyCtrl.CancelMoveRequest();
            }
        }
Beispiel #3
0
        public static RagdollHitInfo CapsuleHitToRagdollHit(Pathea.PECapsuleHitResult hitResult)
        {
            RagdollHitInfo hitInfo = new RagdollHitInfo();

            hitInfo.hitTransform = hitResult.hitTrans;
            hitInfo.hitPoint     = hitResult.hitPos;
            hitInfo.hitForce     = hitResult.hitDir * 1000.0f;
            return(hitInfo);
        }
    public void Activate(RagdollHitInfo hitInfo, bool isGetupReady)
    {
        //if (animFollow.active)
        //    return;

        shotByBullet      = true;
        animFollow.active = true;
        m_GetupReady      = isGetupReady;

        StartCoroutine(AddForce(hitInfo));
    }
        public void ActivateRagdoll(RagdollHitInfo hitInfo = null, bool isGetupReady = true)
        {
            if (monoRagdollCtrlr != null)
            {
                monoRagdollCtrlr.Activate(hitInfo, isGetupReady);
            }

            if (null != cmptIK)
            {
                cmptIK.ikEnable = false;
            }
        }
//    public void AttachJoint(string boneName, Transform boneJoint)
//    {
//        Transform boneChild = PETools.PEUtil.GetChild(transform, boneJoint.name);
//
//        if (boneChild != null)
//            return;
//
//        GameObject joint = GameObject.Instantiate(boneJoint.gameObject) as GameObject;
//        joint.name = PETools.PEUtil.ToPrefabName(joint.name);
//
//        Transform[] transforms = joint.GetComponentsInChildren<Transform>();
//        foreach (Transform tr in transforms)
//        {
//            tr.gameObject.layer = gameObject.layer;
//
//            if (tr.GetComponent<Collider>() != null)
//                GameObject.Destroy(tr.GetComponent<Collider>());
//
//            if (tr.GetComponent<Rigidbody>() != null)
//                GameObject.Destroy(tr.GetComponent<Rigidbody>());
//
//            if (tr.GetComponent<Light>() != null)
//                GameObject.Destroy(tr.GetComponent<Light>());
//
//            if (tr.GetComponent<ParticleSystem>() != null)
//                GameObject.Destroy(tr.GetComponent<ParticleSystem>());
//
//            if (tr.GetComponent<AudioSource>() != null)
//                GameObject.Destroy(tr.GetComponent<AudioSource>());
//        }
//
//        if (master != null && master.GetComponent<Collider>() != null)
//        {
//            Collider[] crs = joint.GetComponentsInChildren<Collider>();
//            foreach (Collider collider in crs)
//            {
//                if(collider.enabled)
//                    Physics.IgnoreCollision(master.GetComponent<Collider>(), collider);
//            }
//        }
//
//        ConfigurableJoint[] joints = boneJoint.GetComponentsInChildren<ConfigurableJoint>();
//        foreach (ConfigurableJoint conf in joints)
//        {
//            GameObject.Destroy(conf);
//
//            Rigidbody rigid = conf.gameObject.GetComponent<Rigidbody>();
//            if (rigid != null)
//                GameObject.Destroy(rigid);
//
//            Collider c = conf.gameObject.GetComponent<Collider>();
//            if (c != null)
//                GameObject.Destroy(c);
//        }
//
//        StartCoroutine(WaitDestroyComponent(boneName, joint));
//    }
//
//    IEnumerator WaitDestroyComponent(string boneName, GameObject joint)
//    {
//        yield return null;
//
//        animFollow.AttachJoint(boneName, joint.transform);
//        m_Handler.OnAttachJoint(joint);
//    }
//
//    public void Reattach(string boneName, Transform boneJoint)
//    {
//        Transform joint = PETools.PEUtil.GetChild(transform, boneJoint.name);
//        if (joint != null)
//        {
//            //animFollow.DetachJoint(joint);
//            //animFollow.AttachJoint(boneName, joint);
//
//            animFollow.Reattach(boneName, boneJoint);
//
//            m_Handler.OnReattachJoint(joint.gameObject);
//        }
//    }
//
//    public void DetachJoint(Transform boneJoint)
//    {
//        Transform boneRagdoll = PETools.PEUtil.GetChild(transform, boneJoint.name);
//        if (null == boneRagdoll)
//        {
//            Debug.LogError("can't find bone of model:" + boneJoint.name);
//            return;
//        }
//
//        animFollow.DetachJoint(boneRagdoll);
//
//        m_Handler.OnDetachJoint(boneRagdoll.gameObject);
//
//        GameObject.Destroy(boneRagdoll.gameObject);
//    }
    #endregion

    #region private func
    IEnumerator AddForce(RagdollHitInfo hitInfo)
    {
        if (hitInfo == null || hitInfo.hitTransform == null)
        {
            yield break;
        }

        yield return(new WaitForFixedUpdate());

        Rigidbody r = hitInfo.hitTransform.GetComponent <Rigidbody>();

        if (r != null)
        {
            r.AddForceAtPosition(hitInfo.hitForce * 100, hitInfo.hitPoint);
        }

        //foreach (Rigidbody rigid in slaveRigidBodies)
        //{
        //    rigid.AddForceAtPosition(hitInfo.hitForce * rigid.mass, rigid.position);
        //}

        //if (ragdollRootBone.GetComponent<Rigidbody>() != null)
        //    ragdollRootBone.GetComponent<Rigidbody>().AddExplosionForce(hitInfo.hitForce.magnitude * 100, hitInfo.hitPoint, 5.0f);
    }