예제 #1
0
    public static Vector3 GetShootPosition(ISkillTarget target)
    {
        SkillRunner runner = target as SkillRunner;

        if (runner != null && runner.GetComponent <Collider>() != null)
        {
            AiObject aiObj = runner as AiObject;
            if (aiObj != null)
            {
                if (aiObj.model != null)
                {
                    Rigidbody[] rigids = aiObj.model.GetComponentsInChildren <Rigidbody>();
                    if (rigids != null && rigids.Length > 0)
                    {
                        return(rigids[Random.Range(0, rigids.Length)].worldCenterOfMass);
                    }
                }

                return(aiObj.center);
            }
            else
            {
                return(AiUtil.GetColliderCenter(runner.GetComponent <Collider>()));
            }
        }
        else
        {
            //CreationSkillRunner creation = runner as CreationSkillRunner;
            //if (creation != null)
            //	return creation.transform.TransformPoint(creation.LocalBounds.center);
            //else
            //	return target.GetPosition();
        }
        return(Vector3.zero);
    }
예제 #2
0
    public static Vector3 GetTargetCenter(ISkillTarget target)
    {
        SkillRunner runner = target as SkillRunner;

        if (runner != null && runner.GetComponent <Collider>() != null)
        {
            AiObject aiObj = runner as AiObject;
            if (aiObj != null)
            {
                return(aiObj.center);
            }
            else
            {
                return(AiUtil.GetColliderCenter(runner.GetComponent <Collider>()));
            }
        }
        else
        {
            //CreationSkillRunner creation = runner as CreationSkillRunner;
            //if (creation != null)
            //return creation.transform.TransformPoint(creation.LocalBounds.center);
            // else
            // return target.GetPosition();
        }
        return(Vector3.zero);
    }
예제 #3
0
    public static Vector3 GetPredictPosition(ISkillTarget target, Vector3 startPos, float speed)
    {
        SkillRunner runner = target as SkillRunner;

        if (runner != null && runner.GetComponent <Rigidbody>() != null)
        {
            Vector3 reverseVec = startPos - GetShootPosition(target);
            float   sqrv22mv12 = Mathf.Sqrt(speed * speed - runner.GetComponent <Rigidbody>().velocity.sqrMagnitude);
            float   cos2       = Mathf.Cos(Vector3.Angle(reverseVec, runner.GetComponent <Rigidbody>().velocity) / 180f * Mathf.PI);
            float   temp1      = reverseVec.sqrMagnitude * runner.GetComponent <Rigidbody>().velocity.sqrMagnitude *cos2 *cos2;
            float   predictTime;
            if (Vector3.Angle(reverseVec, runner.GetComponent <Rigidbody>().velocity) <= 90f)
            {
                predictTime = (Mathf.Sqrt(reverseVec.sqrMagnitude + temp1 / sqrv22mv12 / sqrv22mv12) - Mathf.Sqrt(temp1 / sqrv22mv12 / sqrv22mv12)) / sqrv22mv12;
            }
            else
            {
                predictTime = (Mathf.Sqrt(reverseVec.sqrMagnitude + temp1 / sqrv22mv12 / sqrv22mv12) + Mathf.Sqrt(temp1 / sqrv22mv12 / sqrv22mv12)) / sqrv22mv12;
            }
            Vector3 predictPos = GetShootPosition(target) + runner.GetComponent <Rigidbody>().velocity *predictTime;
            return(predictPos);
        }
        else
        {
            return(GetShootPosition(target));
        }
    }