Ejemplo n.º 1
0
        public void LateInit()
        {
            if (this.TargetingBehavior != TargetingType.Timed)
            {
                this.cachedTransform.position = this.Position.ToVector3();
                this.speedPerFrame            = this.Speed / 32L;
            }



            switch (this.TargetingBehavior)
            {
            case TargetingType.Timed:
                this.CountDown = this.Delay;

                break;

            case TargetingType.Positional:
            case TargetingType.Homing:
                long f         = this.Position.ToVector2d().Distance(this.TargetPosition);
                long timeToHit = f.Div(this.Speed);
                if (this._visualArc)
                {
                    this.arcStartHeight = this.Position.z;
                    if (timeToHit > 0)
                    {
                        this.arcStartVerticalSpeed = (this.TargetHeight - this.Position.z).Div(timeToHit) + timeToHit.Mul(Gravity);
                    }
                }
                else
                {
                    if (timeToHit > 0)
                    {
                        this.linearHeightSpeed = (this.TargetHeight - Position.z).Div(timeToHit).Abs() / LockstepManager.FrameRate;
                    }
                }
                Forward = TargetPosition - this.Position.ToVector2d();
                Forward.Normalize();
                break;

            case TargetingType.Free:

                Vector3d vel = this.Direction;
                vel.Mul(speedPerFrame);
                this.Velocity = vel;


                break;
            }
            if (this.CanRotate)
            {
                this.cachedTransform.LookAt(this.Direction.ToVector3());
            }
            this.UpdateVisuals();

            if (this.onInitialize.IsNotNull())
            {
                this.onInitialize.Invoke();
            }

            if (UseEffects)
            {
                LSEffect effect = EffectManager.LazyCreateEffect(this.StartFX, this.Position.ToVector3(), this.cachedTransform.rotation);
                if (effect != null)
                {
                    effect.StartPos = this.Position.ToVector3();
                    effect.EndPos   = this.TargetPosition.ToVector3(this.TargetHeight.ToFloat());
                    if (this.Target != null)
                    {
                        effect.Target = Target.transform;
                    }
                }
            }
        }