Exemple #1
0
        private void _SetupMove(Vector3D destination, float speed)
        {
            Vector3D dir_normal = PowerMath.Normalize(new Vector3D(destination.X - this.Target.Position.X,
                                                                   destination.Y - this.Target.Position.Y,
                                                                   destination.Z - this.Target.Position.Z));

            this.Velocity = new Vector3D(dir_normal.X * speed,
                                         dir_normal.Y * speed,
                                         dir_normal.Z * speed);

            this.ArrivalTime = new RelativeTickTimer(this.Target.World.Game,
                                                     (int)(PowerMath.Distance2D(this.Target.Position, destination) / speed));
            _startPosition = this.Target.Position;
            _endPosition   = destination;
            _startTick     = this.Target.World.Game.TickCounter;
        }
Exemple #2
0
        private void _SetupArcMove(Vector3D destination, float crestHeight, float gravity)
        {
            // TODO: handle when target and destination heights differ
            float absGravity   = Math.Abs(gravity);
            float arcLength    = (float)Math.Sqrt(2f * crestHeight / absGravity);
            int   arrivalTicks = (int)(arcLength * 2f);

            float    distance = PowerMath.Distance2D(this.Target.Position, destination);
            Vector3D normal   = PowerMath.Normalize(new Vector3D(destination.X - this.Target.Position.X,
                                                                 destination.Y - this.Target.Position.Y,
                                                                 0f));

            this.Velocity = new Vector3D(normal.X * (distance / arrivalTicks),
                                         normal.Y * (distance / arrivalTicks),
                                         absGravity * arcLength);

            this.ArrivalTime = new RelativeTickTimer(this.Target.World.Game, arrivalTicks);
            _startPosition   = this.Target.Position;
            _endPosition     = destination;
            _startTick       = this.Target.World.Game.TickCounter;
            _arcGravity      = gravity;
        }