Exemplo n.º 1
0
        private void CalculateFlight(ArcMover mover, Vector3 target)
        {
            float targetDistance = Vector3.Distance(mover.Entity.Tr.position, target);
            // Calculate the velocity needed to throw the object to the target at specified angle.
            float projectileVelocity = targetDistance / (Mathf.Sin(2 * mover.Angle * Mathf.Deg2Rad) / mover.Speed);

            mover.MoveVector.z = Mathf.Sqrt(projectileVelocity) * Mathf.Cos(mover.Angle * Mathf.Deg2Rad);
            mover.MoveVector.y = Mathf.Sqrt(projectileVelocity) * Mathf.Sin(mover.Angle * Mathf.Deg2Rad);
            // Calculate flight time.
            mover.Duration = targetDistance / mover.MoveVector.z;
            // Rotate projectile to face the target.
            mover.Entity.Tr.rotation = Quaternion.LookRotation(target - mover.Entity.Tr.position);
            mover.ElapsedTime        = 0;
        }
Exemplo n.º 2
0
        private void HandleArcMovement(ArcMover mover)
        {
            var entity = mover.GetEntity();

            if (!entity.Tags.Contain(EntityTags.Moving))
            {
                return;
            }
            mover.ElapsedTime += TimeManager.DeltaTime;
            mover.Entity.Tr.Translate(0, (mover.MoveVector.y - (mover.Speed * mover.ElapsedTime)) * TimeManager.DeltaTime, mover.MoveVector.z * TimeManager.DeltaTime);
            if (mover.ElapsedTime > mover.Duration)
            {
                FinishMove(entity, mover.Entity.Tr.position);
            }
        }
Exemplo n.º 3
0
        private void CalculateFlight(ArcMover mover, Vector3 target, float speed)
        {
            var   tr             = mover.GetEntity().Get <TransformComponent>();
            float targetDistance = Vector3.Distance(tr.position, target);
            // Calculate the velocity needed to throw the object to the target at specified angle.
            float projectileVelocity = targetDistance / (Mathf.Sin(2 * mover.Angle * Mathf.Deg2Rad) / speed);

            mover.MoveVector.z = Mathf.Sqrt(projectileVelocity) * Mathf.Cos(mover.Angle * Mathf.Deg2Rad);
            mover.MoveVector.y = Mathf.Sqrt(projectileVelocity) * Mathf.Sin(mover.Angle * Mathf.Deg2Rad);
            // Calculate flight time.
            mover.Duration = targetDistance / mover.MoveVector.z;
            // Rotate projectile to face the target.
            var entity = mover.GetEntity();

            entity.Post(new SetTransformRotation(entity.Get <TransformComponent>(), Quaternion.LookRotation(target - tr.position)));
            mover.ElapsedTime = 0;
        }