Exemple #1
0
        public ISnapshotInfo lerp(ISnapshotInfo targetTemp, float delta)
        {
            YawSnapshotInfo yawSnapshotInfo = (YawSnapshotInfo)targetTemp;

            return(new YawSnapshotInfo
            {
                pos = Vector3.Lerp(this.pos, yawSnapshotInfo.pos, delta),
                yaw = Mathf.LerpAngle(this.yaw, yawSnapshotInfo.yaw, delta)
            });
        }
Exemple #2
0
 private void Update()
 {
     if (this.isDead)
     {
         return;
     }
     if (Provider.isServer)
     {
         if (!this.isUpdated)
         {
             if (Mathf.Abs(this.lastUpdatePos.x - base.transform.position.x) > Provider.UPDATE_DISTANCE || Mathf.Abs(this.lastUpdatePos.y - base.transform.position.y) > Provider.UPDATE_DISTANCE || Mathf.Abs(this.lastUpdatePos.z - base.transform.position.z) > Provider.UPDATE_DISTANCE || Mathf.Abs(this.lastUpdateAngle - base.transform.rotation.eulerAngles.y) > 1f)
             {
                 this.lastUpdatePos     = base.transform.position;
                 this.lastUpdateAngle   = base.transform.rotation.eulerAngles.y;
                 this.isUpdated         = true;
                 AnimalManager.updates += 1;
                 if (this.isStuck && Time.time - this.lastStuck > 0.5f)
                 {
                     this.isStuck   = false;
                     this.lastStuck = Time.time;
                 }
             }
             else if (this.isMoving)
             {
                 if (Time.time - this.lastStuck > 0.125f)
                 {
                     this.isStuck = true;
                 }
             }
             else
             {
                 this.isStuck   = false;
                 this.lastStuck = Time.time;
             }
         }
     }
     else
     {
         if (Mathf.Abs(this.lastUpdatePos.x - base.transform.position.x) > 0.01f || Mathf.Abs(this.lastUpdatePos.y - base.transform.position.y) > 0.01f || Mathf.Abs(this.lastUpdatePos.z - base.transform.position.z) > 0.01f)
         {
             if (!this.isMoving)
             {
                 if (this.isPlayingEat)
                 {
                     this.animator.Stop();
                     this.isPlayingEat = false;
                 }
                 if (this.isPlayingGlance)
                 {
                     this.animator.Stop();
                     this.isPlayingGlance = false;
                 }
                 if (this.isPlayingStartle)
                 {
                     this.animator.Stop();
                     this.isPlayingStartle = false;
                 }
             }
             this.isMoving  = true;
             this.isRunning = ((this.lastUpdatePos - base.transform.position).sqrMagnitude > 1f);
         }
         else
         {
             this.isMoving  = false;
             this.isRunning = false;
         }
         if (this.nsb != null)
         {
             YawSnapshotInfo yawSnapshotInfo = (YawSnapshotInfo)this.nsb.getCurrentSnapshot();
             base.transform.position = yawSnapshotInfo.pos;
             base.transform.rotation = Quaternion.Euler(0f, yawSnapshotInfo.yaw, 0f);
         }
     }
     if (!Dedicator.isDedicated && !this.isMoving && !this.isPlayingEat && !this.isPlayingGlance && !this.isPlayingAttack)
     {
         if (Time.time - this.lastEat > this.eatDelay)
         {
             this.askEat();
         }
         else if (Time.time - this.lastGlance > this.glanceDelay)
         {
             this.askGlance();
         }
     }
     if (Provider.isServer)
     {
         if (this.isStuck)
         {
             if (Time.time - this.lastStuck > 0.75f)
             {
                 this.lastStuck = Time.time;
                 this.getWanderTarget();
             }
         }
         else if (!this.isFleeing && !this.isHunting)
         {
             if (Time.time - this.lastWander > this.wanderDelay)
             {
                 this.lastWander  = Time.time;
                 this.wanderDelay = Random.Range(8f, 16f);
                 this.getWanderTarget();
             }
         }
         else
         {
             this.lastWander = Time.time;
         }
     }
     if (this.isPlayingEat)
     {
         if (Time.time - this.lastEat > this.eatTime)
         {
             this.isPlayingEat = false;
         }
     }
     else if (this.isPlayingGlance)
     {
         if (Time.time - this.lastGlance > this.glanceTime)
         {
             this.isPlayingGlance = false;
         }
     }
     else if (this.isPlayingStartle)
     {
         if (Time.time - this.lastStartle > this.startleTime)
         {
             this.isPlayingStartle = false;
         }
     }
     else if (this.isPlayingAttack)
     {
         if (Time.time - this.lastAttack > this.attackTime)
         {
             this.isPlayingAttack = false;
         }
     }
     else if (!Dedicator.isDedicated)
     {
         if (this.isRunning)
         {
             this.animator.Play("Run");
         }
         else if (this.isMoving)
         {
             this.animator.Play("Walk");
         }
         else
         {
             this.animator.Play("Idle");
         }
     }
     if (Provider.isServer && this.health < this.asset.health && Time.time - this.lastRegen > this.asset.regen)
     {
         this.lastRegen = Time.time;
         this.health   += 1;
     }
 }