Exemple #1
0
    // Token: 0x060027EC RID: 10220 RVA: 0x000CFCB0 File Offset: 0x000CE0B0
    public static Vector3 Predict(Vector3 sPos, Vector3 tPos, Vector3 tLastPos, float pSpeed)
    {
        Vector3 vector         = (tPos - tLastPos) / Time.deltaTime;
        float   projFlightTime = F3DPredictTrajectory.GetProjFlightTime(tPos - sPos, vector, pSpeed);

        if (projFlightTime > 0f)
        {
            return(tPos + projFlightTime * vector);
        }
        return(tPos);
    }
Exemple #2
0
    // Update is called once per frame
    void Update()
    {
        if (Target)
        {
            Vector3 hitPos = F3DPredictTrajectory.Predict(transform.position, Target.transform.position, targetLastPos, velocity);
            targetLastPos = Target.transform.position;

            transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.LookRotation(hitPos - transform.position), Time.deltaTime * alignSpeed);
        }
        step = transform.forward * Time.deltaTime * velocity;

        transform.position += step;
    }
Exemple #3
0
 // Token: 0x060027E1 RID: 10209 RVA: 0x000CF710 File Offset: 0x000CDB10
 private void Update()
 {
     if (this.isHit)
     {
         if (!this.isFXSpawned)
         {
             F3DMissileLauncher.instance.SpawnExplosion(this.transform.position);
             this.isFXSpawned = true;
         }
         if (!this.DelayDespawn || (this.DelayDespawn && this.timer >= this.despawnDelay))
         {
             this.OnMissileDestroy();
         }
     }
     else
     {
         if (this.target != null)
         {
             if (this.missileType == F3DMissile.MissileType.Predictive)
             {
                 Vector3 a = F3DPredictTrajectory.Predict(this.transform.position, this.target.position, this.targetLastPos, this.velocity);
                 this.targetLastPos      = this.target.position;
                 this.transform.rotation = Quaternion.Lerp(this.transform.rotation, Quaternion.LookRotation(a - this.transform.position), Time.deltaTime * this.alignSpeed);
             }
             else if (this.missileType == F3DMissile.MissileType.Guided)
             {
                 this.transform.rotation = Quaternion.Lerp(this.transform.rotation, Quaternion.LookRotation(this.target.position - this.transform.position), Time.deltaTime * this.alignSpeed);
             }
         }
         this.step = this.transform.forward * Time.deltaTime * this.velocity;
         if (this.target != null && this.missileType != F3DMissile.MissileType.Unguided && Vector3.SqrMagnitude(this.transform.position - this.target.position) <= this.detonationDistance)
         {
             this.OnHit();
         }
         else if (this.missileType == F3DMissile.MissileType.Unguided && Physics.Raycast(this.transform.position, this.transform.forward, this.step.magnitude * this.RaycastAdvance, this.layerMask))
         {
             this.OnHit();
         }
         else if (this.timer >= this.lifeTime)
         {
             this.isFXSpawned = true;
             this.OnHit();
         }
         this.transform.position += this.step;
     }
     this.timer += Time.deltaTime;
 }
    void Update()
    {
        // If something was hit
        if (isHit)
        {
            // Execute once
            if (!isFXSpawned)
            {
                // Put your calls to effect manager that spawns explosion on hit
                // .....

                F3DMissileLauncher.instance.SpawnExplosion(transform.position);

                isFXSpawned = true;
            }

            // Despawn current missile
            if (!DelayDespawn || (DelayDespawn && (timer >= despawnDelay)))
            {
                OnMissileDestroy();
            }
        }
        // No collision occurred yet
        else
        {
            // Navigate
            if (target != null)
            {
                if (missileType == MissileType.Predictive)
                {
                    Vector3 hitPos = F3DPredictTrajectory.Predict(transform.position, target.position, targetLastPos, velocity);
                    targetLastPos = target.position;

                    transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.LookRotation(hitPos - transform.position), Time.deltaTime * alignSpeed);
                }
                else if (missileType == MissileType.Guided)
                {
                    transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.LookRotation(target.position - transform.position), Time.deltaTime * alignSpeed);
                }
            }

            // Missile step per frame based on velocity and time
            step = transform.forward * Time.deltaTime * velocity;

            if (target != null && missileType != MissileType.Unguided && Vector3.SqrMagnitude(transform.position - target.position) <= detonationDistance)
            {
                OnHit();
            }
            else if (missileType == MissileType.Unguided && Physics.Raycast(transform.position, transform.forward, step.magnitude * RaycastAdvance, layerMask))
            {
                OnHit();
            }
            // Nothing hit
            else
            {
                // Despawn missile at the end of life cycle
                if (timer >= lifeTime)
                {
                    // Do not detonate
                    isFXSpawned = true;
                    OnHit();
                }
            }

            // Advances missile forward
            transform.position += step;
        }

        // Updates missile timer
        timer += Time.deltaTime;
    }