コード例 #1
0
ファイル: Horse.cs プロジェクト: Jagerente/GucciGangMod
    private void LateUpdate()
    {
        if (myHero == null && photonView.isMine)
        {
            PhotonNetwork.Destroy(gameObject);
        }

        if (State == "mounted")
        {
            if (myHero == null)
            {
                unmounted();
                return;
            }

            myHero.transform.position = transform.position + Vector3.up * 1.68f;
            myHero.transform.rotation = transform.rotation;
            myHero.rigidbody.velocity = rigidbody.velocity;
            if (controller.targetDirection != -874f)
            {
                gameObject.transform.rotation = Quaternion.Lerp(gameObject.transform.rotation, Quaternion.Euler(0f, controller.targetDirection, 0f), 100f * Time.deltaTime / (rigidbody.velocity.magnitude + 20f));
                if (controller.isWALKDown)
                {
                    rigidbody.AddForce(transform.forward * speed * 0.6f, ForceMode.Acceleration);
                    if (rigidbody.velocity.magnitude >= speed * 0.6f)
                    {
                        rigidbody.AddForce(-speed * 0.6f * rigidbody.velocity.normalized, ForceMode.Acceleration);
                    }
                }
                else
                {
                    rigidbody.AddForce(transform.forward * speed, ForceMode.Acceleration);
                    if (rigidbody.velocity.magnitude >= speed)
                    {
                        rigidbody.AddForce(-speed * rigidbody.velocity.normalized, ForceMode.Acceleration);
                    }
                }

                if (rigidbody.velocity.magnitude > 8f)
                {
                    if (!animation.IsPlaying("horse_Run"))
                    {
                        crossFade("horse_Run", 0.1f);
                    }

                    if (!myHero.animation.IsPlaying("horse_Run"))
                    {
                        myHero.GetComponent <HERO>().crossFade("horse_run", 0.1f);
                    }

                    if (!dust.GetComponent <ParticleSystem>().enableEmission)
                    {
                        dust.GetComponent <ParticleSystem>().enableEmission = true;
                        object[] parameters = { true };
                        photonView.RPC("setDust", PhotonTargets.Others, parameters);
                    }
                }
                else
                {
                    if (!animation.IsPlaying("horse_WALK"))
                    {
                        crossFade("horse_WALK", 0.1f);
                    }

                    if (!myHero.animation.IsPlaying("horse_idle"))
                    {
                        myHero.GetComponent <HERO>().crossFade("horse_idle", 0.1f);
                    }

                    if (dust.GetComponent <ParticleSystem>().enableEmission)
                    {
                        dust.GetComponent <ParticleSystem>().enableEmission = false;
                        object[] objArray2 = { false };
                        photonView.RPC("setDust", PhotonTargets.Others, objArray2);
                    }
                }
            }
            else
            {
                toIdleAnimation();
                if (rigidbody.velocity.magnitude > 15f)
                {
                    if (!myHero.animation.IsPlaying("horse_Run"))
                    {
                        myHero.GetComponent <HERO>().crossFade("horse_run", 0.1f);
                    }
                }
                else if (!myHero.animation.IsPlaying("horse_idle"))
                {
                    myHero.GetComponent <HERO>().crossFade("horse_idle", 0.1f);
                }
            }

            if ((controller.isAttackDown || controller.isAttackIIDown) && IsGrounded())
            {
                rigidbody.AddForce(Vector3.up * 25f, ForceMode.VelocityChange);
            }
        }
        else if (State == "follow")
        {
            if (myHero == null)
            {
                unmounted();
                return;
            }

            if (rigidbody.velocity.magnitude > 8f)
            {
                if (!animation.IsPlaying("horse_Run"))
                {
                    crossFade("horse_Run", 0.1f);
                }

                if (!dust.GetComponent <ParticleSystem>().enableEmission)
                {
                    dust.GetComponent <ParticleSystem>().enableEmission = true;
                    object[] objArray3 = { true };
                    photonView.RPC("setDust", PhotonTargets.Others, objArray3);
                }
            }
            else
            {
                if (!animation.IsPlaying("horse_WALK"))
                {
                    crossFade("horse_WALK", 0.1f);
                }

                if (dust.GetComponent <ParticleSystem>().enableEmission)
                {
                    dust.GetComponent <ParticleSystem>().enableEmission = false;
                    object[] objArray4 = { false };
                    photonView.RPC("setDust", PhotonTargets.Others, objArray4);
                }
            }

            var num = -Mathf.DeltaAngle(FengMath.getHorizontalAngle(transform.position, setPoint), gameObject.transform.rotation.eulerAngles.y - 90f);
            gameObject.transform.rotation = Quaternion.Lerp(gameObject.transform.rotation, Quaternion.Euler(0f, gameObject.transform.rotation.eulerAngles.y + num, 0f), 200f * Time.deltaTime / (rigidbody.velocity.magnitude + 20f));
            if (Vector3.Distance(setPoint, transform.position) < 20f)
            {
                rigidbody.AddForce(transform.forward * speed * 0.7f, ForceMode.Acceleration);
                if (rigidbody.velocity.magnitude >= speed)
                {
                    rigidbody.AddForce(-speed * 0.7f * rigidbody.velocity.normalized, ForceMode.Acceleration);
                }
            }
            else
            {
                rigidbody.AddForce(transform.forward * speed, ForceMode.Acceleration);
                if (rigidbody.velocity.magnitude >= speed)
                {
                    rigidbody.AddForce(-speed * rigidbody.velocity.normalized, ForceMode.Acceleration);
                }
            }

            timeElapsed += Time.deltaTime;
            if (timeElapsed > 0.6f)
            {
                timeElapsed = 0f;
                if (Vector3.Distance(myHero.transform.position, setPoint) > 20f)
                {
                    followed();
                }
            }

            if (Vector3.Distance(myHero.transform.position, transform.position) < 5f)
            {
                unmounted();
            }

            if (Vector3.Distance(setPoint, transform.position) < 5f)
            {
                unmounted();
            }

            awayTimer += Time.deltaTime;
            if (awayTimer > 6f)
            {
                awayTimer = 0f;
                LayerMask mask2 = 1 << LayerMask.NameToLayer("Ground");
                if (Physics.Linecast(transform.position + Vector3.up, myHero.transform.position + Vector3.up, mask2.value))
                {
                    transform.position = new Vector3(myHero.transform.position.x, getHeight(myHero.transform.position + Vector3.up * 5f), myHero.transform.position.z);
                }
            }
        }
        else if (State == "idle")
        {
            toIdleAnimation();
            if (myHero != null && Vector3.Distance(myHero.transform.position, transform.position) > 20f)
            {
                followed();
            }
        }

        rigidbody.AddForce(new Vector3(0f, -50f * rigidbody.mass, 0f));
    }
コード例 #2
0
ファイル: Horse.cs プロジェクト: rnetiks/CyanModSRC
 private void LateUpdate()
 {
     if ((this.myHero == null) && base.photonView.isMine)
     {
         PhotonNetwork.Destroy(base.gameObject);
     }
     if (this.State == "mounted")
     {
         if (this.myHero == null)
         {
             this.unmounted();
             return;
         }
         this.myHero.transform.position = base.transform.position + ((Vector3)(Vector3.up * 1.68f));
         this.myHero.transform.rotation = base.transform.rotation;
         this.myHero.rigidbody.velocity = base.rigidbody.velocity;
         if (this.controller.targetDirection != -874f)
         {
             base.gameObject.transform.rotation = Quaternion.Lerp(base.gameObject.transform.rotation, Quaternion.Euler(0f, this.controller.targetDirection, 0f), (100f * Time.deltaTime) / (base.rigidbody.velocity.magnitude + 20f));
             if (this.controller.isWALKDown)
             {
                 base.rigidbody.AddForce((Vector3)((base.transform.forward * this.speed) * 0.6f), ForceMode.Acceleration);
                 if (base.rigidbody.velocity.magnitude >= (this.speed * 0.6f))
                 {
                     base.rigidbody.AddForce((Vector3)((-this.speed * 0.6f) * base.rigidbody.velocity.normalized), ForceMode.Acceleration);
                 }
             }
             else
             {
                 base.rigidbody.AddForce((Vector3)(base.transform.forward * this.speed), ForceMode.Acceleration);
                 if (base.rigidbody.velocity.magnitude >= this.speed)
                 {
                     base.rigidbody.AddForce((Vector3)(-this.speed * base.rigidbody.velocity.normalized), ForceMode.Acceleration);
                 }
             }
             if (base.rigidbody.velocity.magnitude > 8f)
             {
                 if (!base.animation.IsPlaying("horse_Run"))
                 {
                     this.crossFade("horse_Run", 0.1f);
                 }
                 if (!this.myHero.animation.IsPlaying("horse_Run"))
                 {
                     this.myHero.GetComponent <HERO>().crossFade("horse_run", 0.1f);
                 }
                 if (!this.dust.GetComponent <ParticleSystem>().enableEmission)
                 {
                     this.dust.GetComponent <ParticleSystem>().enableEmission = true;
                     object[] parameters = new object[] { true };
                     base.photonView.RPC("setDust", PhotonTargets.Others, parameters);
                 }
             }
             else
             {
                 if (!base.animation.IsPlaying("horse_WALK"))
                 {
                     this.crossFade("horse_WALK", 0.1f);
                 }
                 if (!this.myHero.animation.IsPlaying("horse_idle"))
                 {
                     this.myHero.GetComponent <HERO>().crossFade("horse_idle", 0.1f);
                 }
                 if (this.dust.GetComponent <ParticleSystem>().enableEmission)
                 {
                     this.dust.GetComponent <ParticleSystem>().enableEmission = false;
                     object[] objArray2 = new object[] { false };
                     base.photonView.RPC("setDust", PhotonTargets.Others, objArray2);
                 }
             }
         }
         else
         {
             this.toIdleAnimation();
             if (base.rigidbody.velocity.magnitude > 15f)
             {
                 if (!this.myHero.animation.IsPlaying("horse_Run"))
                 {
                     this.myHero.GetComponent <HERO>().crossFade("horse_run", 0.1f);
                 }
             }
             else if (!this.myHero.animation.IsPlaying("horse_idle"))
             {
                 this.myHero.GetComponent <HERO>().crossFade("horse_idle", 0.1f);
             }
         }
         if ((this.controller.isAttackDown || this.controller.isAttackIIDown) && this.IsGrounded())
         {
             base.rigidbody.AddForce((Vector3)(Vector3.up * 25f), ForceMode.VelocityChange);
         }
     }
     else if (this.State == "follow")
     {
         if (this.myHero == null)
         {
             this.unmounted();
             return;
         }
         if (base.rigidbody.velocity.magnitude > 8f)
         {
             if (!base.animation.IsPlaying("horse_Run"))
             {
                 this.crossFade("horse_Run", 0.1f);
             }
             if (!this.dust.GetComponent <ParticleSystem>().enableEmission)
             {
                 this.dust.GetComponent <ParticleSystem>().enableEmission = true;
                 object[] objArray3 = new object[] { true };
                 base.photonView.RPC("setDust", PhotonTargets.Others, objArray3);
             }
         }
         else
         {
             if (!base.animation.IsPlaying("horse_WALK"))
             {
                 this.crossFade("horse_WALK", 0.1f);
             }
             if (this.dust.GetComponent <ParticleSystem>().enableEmission)
             {
                 this.dust.GetComponent <ParticleSystem>().enableEmission = false;
                 object[] objArray4 = new object[] { false };
                 base.photonView.RPC("setDust", PhotonTargets.Others, objArray4);
             }
         }
         float num = -Mathf.DeltaAngle(FengMath.getHorizontalAngle(base.transform.position, this.setPoint), base.gameObject.transform.rotation.eulerAngles.y - 90f);
         base.gameObject.transform.rotation = Quaternion.Lerp(base.gameObject.transform.rotation, Quaternion.Euler(0f, base.gameObject.transform.rotation.eulerAngles.y + num, 0f), (200f * Time.deltaTime) / (base.rigidbody.velocity.magnitude + 20f));
         if (Vector3.Distance(this.setPoint, base.transform.position) < 20f)
         {
             base.rigidbody.AddForce((Vector3)((base.transform.forward * this.speed) * 0.7f), ForceMode.Acceleration);
             if (base.rigidbody.velocity.magnitude >= this.speed)
             {
                 base.rigidbody.AddForce((Vector3)((-this.speed * 0.7f) * base.rigidbody.velocity.normalized), ForceMode.Acceleration);
             }
         }
         else
         {
             base.rigidbody.AddForce((Vector3)(base.transform.forward * this.speed), ForceMode.Acceleration);
             if (base.rigidbody.velocity.magnitude >= this.speed)
             {
                 base.rigidbody.AddForce((Vector3)(-this.speed * base.rigidbody.velocity.normalized), ForceMode.Acceleration);
             }
         }
         this.timeElapsed += Time.deltaTime;
         if (this.timeElapsed > 0.6f)
         {
             this.timeElapsed = 0f;
             if (Vector3.Distance(this.myHero.transform.position, this.setPoint) > 20f)
             {
                 this.followed();
             }
         }
         if (Vector3.Distance(this.myHero.transform.position, base.transform.position) < 5f)
         {
             this.unmounted();
         }
         if (Vector3.Distance(this.setPoint, base.transform.position) < 5f)
         {
             this.unmounted();
         }
         this.awayTimer += Time.deltaTime;
         if (this.awayTimer > 6f)
         {
             this.awayTimer = 0f;
             LayerMask mask = ((int)1) << LayerMask.NameToLayer("Ground");
             if (Physics.Linecast(base.transform.position + Vector3.up, this.myHero.transform.position + Vector3.up, mask.value))
             {
                 base.transform.position = new Vector3(this.myHero.transform.position.x, this.getHeight(this.myHero.transform.position + ((Vector3)(Vector3.up * 5f))), this.myHero.transform.position.z);
             }
         }
     }
     else if (this.State == "idle")
     {
         this.toIdleAnimation();
         if ((this.myHero != null) && (Vector3.Distance(this.myHero.transform.position, base.transform.position) > 20f))
         {
             this.followed();
         }
     }
     base.rigidbody.AddForce(new Vector3(0f, -50f * base.rigidbody.mass, 0f));
 }
コード例 #3
0
ファイル: Horse.cs プロジェクト: Mi-Sad/guardian
    private void LateUpdate()
    {
        if (myHero == null && base.photonView.isMine)
        {
            PhotonNetwork.Destroy(base.gameObject);
        }
        switch (State)
        {
        case "mounted":
            if (myHero == null)
            {
                Unmount();
                return;
            }
            myHero.transform.position = base.transform.position + Vector3.up * 1.68f;
            myHero.transform.rotation = base.transform.rotation;
            myHero.rigidbody.velocity = base.rigidbody.velocity;
            if (controller.targetDirection != -874f)
            {
                base.gameObject.transform.rotation = Quaternion.Lerp(base.gameObject.transform.rotation, Quaternion.Euler(0f, controller.targetDirection, 0f), 100f * Time.deltaTime / (base.rigidbody.velocity.magnitude + 20f));
                if (controller.isWALKDown)
                {
                    base.rigidbody.AddForce(base.transform.forward * speed * 0.6f, ForceMode.Acceleration);
                    if (!(base.rigidbody.velocity.magnitude < speed * 0.6f))
                    {
                        base.rigidbody.AddForce((0f - speed) * 0.6f * base.rigidbody.velocity.normalized, ForceMode.Acceleration);
                    }
                }
                else
                {
                    base.rigidbody.AddForce(base.transform.forward * speed, ForceMode.Acceleration);
                    if (!(base.rigidbody.velocity.magnitude < speed))
                    {
                        base.rigidbody.AddForce((0f - speed) * base.rigidbody.velocity.normalized, ForceMode.Acceleration);
                    }
                }
                if (base.rigidbody.velocity.magnitude > 8f)
                {
                    if (!base.animation.IsPlaying("horse_Run"))
                    {
                        CrossFade("horse_Run", 0.1f);
                    }
                    if (!myHero.animation.IsPlaying("horse_Run"))
                    {
                        myHero.GetComponent <HERO>().CrossFade("horse_run", 0.1f);
                    }
                    if (!dust.GetComponent <ParticleSystem>().enableEmission)
                    {
                        dust.GetComponent <ParticleSystem>().enableEmission = true;
                        base.photonView.RPC("setDust", PhotonTargets.Others, true);
                    }
                }
                else
                {
                    if (!base.animation.IsPlaying("horse_WALK"))
                    {
                        CrossFade("horse_WALK", 0.1f);
                    }
                    if (!myHero.animation.IsPlaying("horse_idle"))
                    {
                        myHero.GetComponent <HERO>().CrossFade("horse_idle", 0.1f);
                    }
                    if (dust.GetComponent <ParticleSystem>().enableEmission)
                    {
                        dust.GetComponent <ParticleSystem>().enableEmission = false;
                        base.photonView.RPC("setDust", PhotonTargets.Others, false);
                    }
                }
            }
            else
            {
                Idle();
                if (base.rigidbody.velocity.magnitude > 15f)
                {
                    if (!myHero.animation.IsPlaying("horse_Run"))
                    {
                        myHero.GetComponent <HERO>().CrossFade("horse_run", 0.1f);
                    }
                }
                else if (!myHero.animation.IsPlaying("horse_idle"))
                {
                    myHero.GetComponent <HERO>().CrossFade("horse_idle", 0.1f);
                }
            }
            if ((controller.isAttackDown || controller.isAttackIIDown) && IsGrounded())
            {
                base.rigidbody.AddForce(Vector3.up * 25f, ForceMode.VelocityChange);
            }
            break;

        case "follow":
            if (myHero == null)
            {
                Unmount();
                return;
            }
            if (base.rigidbody.velocity.magnitude > 8f)
            {
                if (!base.animation.IsPlaying("horse_Run"))
                {
                    CrossFade("horse_Run", 0.1f);
                }
                if (!dust.GetComponent <ParticleSystem>().enableEmission)
                {
                    dust.GetComponent <ParticleSystem>().enableEmission = true;
                    base.photonView.RPC("setDust", PhotonTargets.Others, true);
                }
            }
            else
            {
                if (!base.animation.IsPlaying("horse_WALK"))
                {
                    CrossFade("horse_WALK", 0.1f);
                }
                if (dust.GetComponent <ParticleSystem>().enableEmission)
                {
                    dust.GetComponent <ParticleSystem>().enableEmission = false;
                    base.photonView.RPC("setDust", PhotonTargets.Others, false);
                }
            }
            float      horizontalAngle = FengMath.getHorizontalAngle(base.transform.position, setPoint);
            Vector3    eulerAngles     = base.gameObject.transform.rotation.eulerAngles;
            float      num             = 0f - Mathf.DeltaAngle(horizontalAngle, eulerAngles.y - 90f);
            Transform  transform       = base.gameObject.transform;
            Quaternion rotation        = base.gameObject.transform.rotation;
            Vector3    eulerAngles2    = base.gameObject.transform.rotation.eulerAngles;
            transform.rotation = Quaternion.Lerp(rotation, Quaternion.Euler(0f, eulerAngles2.y + num, 0f), 200f * Time.deltaTime / (base.rigidbody.velocity.magnitude + 20f));
            if (Vector3.Distance(setPoint, base.transform.position) < 20f)
            {
                base.rigidbody.AddForce(base.transform.forward * speed * 0.7f, ForceMode.Acceleration);
                if (!(base.rigidbody.velocity.magnitude < speed))
                {
                    base.rigidbody.AddForce((0f - speed) * 0.7f * base.rigidbody.velocity.normalized, ForceMode.Acceleration);
                }
            }
            else
            {
                base.rigidbody.AddForce(base.transform.forward * speed, ForceMode.Acceleration);
                if (!(base.rigidbody.velocity.magnitude < speed))
                {
                    base.rigidbody.AddForce((0f - speed) * base.rigidbody.velocity.normalized, ForceMode.Acceleration);
                }
            }
            timeElapsed += Time.deltaTime;
            if (timeElapsed > 0.6f)
            {
                timeElapsed = 0f;
                if (Vector3.Distance(myHero.transform.position, setPoint) > 20f)
                {
                    Follow();
                }
            }
            if (Vector3.Distance(myHero.transform.position, base.transform.position) < 5f)
            {
                Unmount();
            }
            if (Vector3.Distance(setPoint, base.transform.position) < 5f)
            {
                Unmount();
            }
            awayTimer += Time.deltaTime;
            if (awayTimer > 6f)
            {
                awayTimer = 0f;
                LayerMask layerMask  = 1 << LayerMask.NameToLayer("Ground");
                LayerMask layerMask2 = layerMask;
                if (Physics.Linecast(base.transform.position + Vector3.up, myHero.transform.position + Vector3.up, layerMask2.value))
                {
                    Transform transform2 = base.transform;
                    Vector3   position   = myHero.transform.position;
                    float     x          = position.x;
                    float     height     = GetHeight(myHero.transform.position + Vector3.up * 5f);
                    Vector3   position2  = myHero.transform.position;
                    transform2.position = new Vector3(x, height, position2.z);
                }
            }
            break;

        case "idle":
            Idle();
            if (myHero != null && Vector3.Distance(myHero.transform.position, base.transform.position) > 20f)
            {
                Follow();
            }
            break;
        }
        base.rigidbody.AddForce(new Vector3(0f, -50f * base.rigidbody.mass, 0f));
    }