Exemplo n.º 1
0
    void GrabObject(GrabbableCollider _grabCol)
    {
        if (!_grabCol)
        {
            return;
        }

        // 掴み中オブジェクトに設定
        GrabObj        = _grabCol.Obj;
        GrabObj.IsGrab = true;

        // 掴み中オブジェクトの掴まれる前の状態を保持
        GrabObj.SetDefaultState();

        // 掴み中オブジェクトの親を自身に設定
        GrabObj.transform.parent = transform;

        // 掴み中オブジェクトのRigidbodyのIsKinamaticをtrueに
        GrabObj.GetComponent <Rigidbody>().isKinematic = true;

        // 設定によって位置や向きの補正を行う
        switch (GrabObj.CorrectType)
        {
        case GrabbableObject.GrabCorrectType.ColliderCenterPositionCorrectGrab:
            transform.position = _grabCol.GetComponent <Collider>().bounds.center;
            break;

        case GrabbableObject.GrabCorrectType.ColliderCenterPositionAndTransformRotationCorrectGrab:
            transform.position = _grabCol.GetComponent <Collider>().bounds.center;
            transform.rotation = _grabCol.transform.rotation;
            break;
        }
    }
Exemplo n.º 2
0
 public void grab()
 {
     if (PlayerGrimoire.GetInstance()._grabObj)
     {
         if (GrabObj)
         {
             GetComponent <OcelotProperties>()._hasObj = true;
             GrabObj.GetComponent <EnchantableObj>().followCat();
         }
     }
 }
Exemplo n.º 3
0
    public void Drop()
    {
        if (!CurrentGrabbedObj)
            return;

        Rigidbody targetbody = CurrentGrabbedObj.GetComponent<Rigidbody>();
        targetbody.velocity = m_Pose.GetVelocity();
        targetbody.angularVelocity = m_Pose.GetAngularVelocity();

        FJ.connectedBody = null;

        CurrentGrabbedObj.activeHand = null;
        CurrentGrabbedObj = null;

    }
Exemplo n.º 4
0
    public void Pickup()
    {
        Debug.Log("attemping to grab nearest");
        CurrentGrabbedObj = GetNearestObj();

        if (!CurrentGrabbedObj)
            return;

        if (CurrentGrabbedObj.activeHand)
            CurrentGrabbedObj.activeHand.Drop();

        CurrentGrabbedObj.transform.position = transform.position;

        Rigidbody targetbody = CurrentGrabbedObj.GetComponent<Rigidbody>();

        FJ.connectedBody = targetbody;

        CurrentGrabbedObj.activeHand = this;
    }
Exemplo n.º 5
0
    void ReleaseObject()
    {
        // 掴み中オブジェクトの親を元に戻す
        //GrabObj.transform.parent = GrabObj.DefParent;
        // 掴み中オブジェクトの親オブジェクトを無くす
        GrabObj.transform.parent = null;
        GrabObj.IsGrab           = false;

        // 掴み中オブジェクトのRigidbodyのIsKinematicを元に戻す
        //GrabObj.GetComponent<Rigidbody>().isKinematic = GrabObj.DefIsKinematic;
        // 掴み中オブジェクトのRigidbodyのIsKinematicをfalseに
        GrabObj.GetComponent <Rigidbody>().isKinematic = false;

        // コントローラーの移動量と回転量をオブジェクトにコピー
        GrabObj.GetComponent <Rigidbody>().velocity        = Controller.velocity;
        GrabObj.GetComponent <Rigidbody>().angularVelocity = Controller.angularVelocity;

        // 掴み中オブジェクトから解除
        GrabObj = null;
    }
Exemplo n.º 6
0
    private GrabObj GetNearestObj()
    {
        Debug.Log("attempting to find nearest");
        GrabObj nearest = null;
        float mindist = float.MaxValue;
        float dist = 0.0f;

        foreach(GrabObj grabObj in contactGrabObj)
        {
            Debug.Log("check each obj");
            dist = (grabObj.transform.position - transform.position).sqrMagnitude;

            if (dist < mindist)
            {
                Debug.Log("set nearest");
                mindist = dist;
                nearest = grabObj;
            }
        }

        return nearest;
    }
Exemplo n.º 7
0
    public void CastSpell()
    {
        //casts the spell that is set to be cast
        if (currentspell == "")
        {
            if (!toggled)
            {
                toggled = true;
                grabbing = true;
                Pickup();
            }
        }

        //Fire Based spells
        else if (currentspell == "FireThrower")
        {
            if (!toggled)
            {                
                toggled = true;
            }
        }
        else if (currentspell == "FireBolt")
        {
            GameObject FireBolt = Instantiate(GameObject.Find("PlayerController").GetComponent<SpellPrefabHolder>().FireBolt, transform.position, transform.rotation);

            FireBolt.GetComponent<Rigidbody>().AddRelativeForce(0, -8000, 8000);
        }
        else if (currentspell == "FireBall")
        {
            GameObject FireBall = Instantiate(GameObject.Find("PlayerController").GetComponent<SpellPrefabHolder>().FireBall, transform.position, transform.rotation);

            FireBall.GetComponent<Rigidbody>().AddRelativeForce(0, -8000, 8000);
        }
        else if (currentspell == "FireSword")
        {
            if (!toggled)
            {
                GameObject FireSword = Instantiate(GameObject.Find("PlayerController").GetComponent<SpellPrefabHolder>().FireSword, transform.position, transform.rotation);
                currentToggle = FireSword;
                toggled = true;
                grabbing = true;

                CurrentGrabbedObj = FireSword.GetComponent<GrabObj>();

                if (CurrentGrabbedObj.activeHand)
                    CurrentGrabbedObj.activeHand.Drop();

                CurrentGrabbedObj.transform.position = transform.position;

                Rigidbody targetbody = CurrentGrabbedObj.GetComponent<Rigidbody>();

                FJ.connectedBody = targetbody;

                CurrentGrabbedObj.activeHand = this;
            }
        }



        //Ice Based spells
        else if (currentspell == "SnowStorm")
        {
            if (!toggled)
            {

                toggled = true;
            }
        }
        else if (currentspell == "IceBolt")
        {
            GameObject IceBolt = Instantiate(GameObject.Find("PlayerController").GetComponent<SpellPrefabHolder>().IceBolt, transform.position, transform.rotation);

            IceBolt.GetComponent<Rigidbody>().AddRelativeForce(0, -8000, 8000);            
        }
        else if (currentspell == "IceBall")
        {
            GameObject Iceball = Instantiate(GameObject.Find("PlayerController").GetComponent<SpellPrefabHolder>().IceBall, transform.position, transform.rotation);

            Iceball.GetComponent<Rigidbody>().AddRelativeForce(0, -8000, 8000);
        }
        else if (currentspell == "IceSword")
        {
            if (!toggled)
            {
                GameObject IceSword = Instantiate(GameObject.Find("PlayerController").GetComponent<SpellPrefabHolder>().IceSword, transform.position, transform.rotation);
                currentToggle = IceSword;
                toggled = true;
                grabbing = true;

                CurrentGrabbedObj = IceSword.GetComponent<GrabObj>();

                if (CurrentGrabbedObj.activeHand)
                    CurrentGrabbedObj.activeHand.Drop();

                CurrentGrabbedObj.transform.position = transform.position;

                Rigidbody targetbody = CurrentGrabbedObj.GetComponent<Rigidbody>();

                FJ.connectedBody = targetbody;

                CurrentGrabbedObj.activeHand = this;
            }
        }



        //Earth Based spells
        else if (currentspell == "RockPillar")
        {
            GameObject RockPillar = Instantiate(GameObject.Find("PlayerController").GetComponent<SpellPrefabHolder>().RockPillar, transform.position, transform.rotation);

            RockPillar.GetComponent<Rigidbody>().AddRelativeForce(0, -8000, 8000);
        }



        //Air Based spells
        else if (currentspell == "AirBurst")
        {
            GameObject AirBurst = Instantiate(GameObject.Find("PlayerController").GetComponent<SpellPrefabHolder>().AirBurst, transform.position, transform.rotation);            
        }
        else if (currentspell == "JumpBoost")
        {
            GameObject.Find("PlayerController").GetComponent<InputRight>().JumpBoost();
        }
        else if (currentspell == "Haste")
        {
            GameObject.Find("PlayerController").GetComponent<InputLeft>().haste();
        }


    }
Exemplo n.º 8
0
    void Update()
    {
        // 何も掴んでいない場合
        if (!IsGrabbing)
        {
            // 掴み操作が有効だったオブジェクトを取得
            List <GrabbableObject> grabbingObjList = new List <GrabbableObject>();
            foreach (var grabObj in grabObjList)
            {
                if (grabObj.CheckGrabInput(Controller))
                {
                    grabbingObjList.Add(grabObj);
                }
            }
            // 掴み操作が有効なオブジェクトが存在すれば
            if (grabbingObjList.Count > 0)
            {
                // 最も位置の近いオブジェクトを掴む対象として取得
                GrabbableObject grabTargetObj = null;
                float           nearDis       = float.MaxValue;
                foreach (var grabbingObj in grabbingObjList)
                {
                    if (!grabbingObj)
                    {
                        continue;
                    }
                    float dis = Vector3.Distance(transform.position, grabbingObj.transform.position);
                    if (nearDis > dis)
                    {
                        nearDis       = dis;
                        grabTargetObj = grabbingObj;
                    }
                }

                // 掴むオブジェクトの掴めるコライダーを取得
                List <GrabbableCollider> grabbingColList = new List <GrabbableCollider>();
                foreach (var grabCol in grabColList)
                {
                    if (grabCol.Obj == grabTargetObj)
                    {
                        grabbingColList.Add(grabCol);
                    }
                }

                // 最も向きの近いTransformに付いているコライダーを掴むコライダーとして取得
                GrabbableCollider grabTargetCol = null;
                float             nearAngle     = float.MaxValue;
                foreach (var grabbingCol in grabbingColList)
                {
                    if (!grabbingCol)
                    {
                        continue;
                    }
                    float angle = Vector3.Dot(transform.forward, grabbingCol.transform.forward);
                    if (nearAngle > angle)
                    {
                        nearAngle     = angle;
                        grabTargetCol = grabbingCol;
                    }
                }

                // 掴む
                GrabObject(grabTargetCol);
            }
        }
        // 既に何か掴んでいる場合
        else
        {
            // 離し操作が有効であれば
            if (GrabObj.CheckReleaseInput(Controller))
            {
                // 離す
                ReleaseObject();
            }
        }
    }