예제 #1
0
    public BallisticProjectileControlHandler(
        ProjectileController projectileController,
        BallisticTrajectorySettings ballisticTrajectorySettings,
        Vector3?maxVelocity)
        : base(projectileController)
    {
        _ballisticTrajectorySettings = ballisticTrajectorySettings;

        _velocity = DynamicsUtility.GetBallisticVelocity(
            _projectileController.gameObject.transform.position + new Vector3(ballisticTrajectorySettings.EndPosition.x, ballisticTrajectorySettings.EndPosition.y, _projectileController.gameObject.transform.position.z),
            _projectileController.gameObject.transform.position,
            ballisticTrajectorySettings.Angle,
            ballisticTrajectorySettings.ProjectileGravity);

        if (maxVelocity.HasValue)
        {
            if (Mathf.Abs(_velocity.x) > maxVelocity.Value.x)
            {
                _velocity.x = maxVelocity.Value.x * Mathf.Sign(_velocity.x);
            }

            if (Mathf.Abs(_velocity.y) > maxVelocity.Value.y)
            {
                _velocity.y = maxVelocity.Value.y * Mathf.Sign(_velocity.y);
            }
        }
    }
예제 #2
0
    public override bool TryActivate(BaseControlHandler previousControlHandler)
    {
        var targetPosition = _enemyController.gameObject.transform.position
                             + new Vector3(
            _ballisticTrajectorySettings.EndPosition.x * _moveDirectionFactor,
            _ballisticTrajectorySettings.EndPosition.y,
            _enemyController.gameObject.transform.position.z);

        _velocity = DynamicsUtility.GetBallisticVelocity(
            targetPosition,
            _enemyController.gameObject.transform.position,
            _ballisticTrajectorySettings.Angle,
            _ballisticTrajectorySettings.ProjectileGravity);

        return(true);
    }
예제 #3
0
    public BallisticTrajectoryControlHandler(CharacterPhysicsManager characterPhysicsManager, Vector3 startPosition, Vector3 endPosition, float gravity
                                             , float angle)
        : base(characterPhysicsManager)
    {
        base.doDrawDebugBoundingBox = true;
        base.debugBoundingBoxColor  = Color.cyan;

        if (characterPhysicsManager != null)
        {
            characterPhysicsManager.onControllerBecameGrounded += (GameObject obj) =>
            {
                _keepAlive = false;
            };
        }

        _gravity  = gravity;
        _velocity = DynamicsUtility.GetBallisticVelocity(endPosition, startPosition, angle, _gravity);

        Logger.Trace("Ballistic start velocity: " + _velocity + ", (startPosition: " + startPosition + ", endPosition: " + endPosition + ", gravity: " + gravity + ", angle: " + angle + ")");
    }
예제 #4
0
    public BallisticTrajectoryControlHandler(
        CharacterPhysicsManager characterPhysicsManager,
        Vector3 startPosition,
        Vector3 endPosition,
        float gravity,
        float angle)
        : base(characterPhysicsManager)
    {
        SetDebugDraw(Color.cyan, true);

        if (characterPhysicsManager != null)
        {
            characterPhysicsManager.ControllerBecameGrounded +=
                _ => _controlHandlerUpdateStatus              = ControlHandlerAfterUpdateStatus.CanBeDisposed;
        }

        _gravity = gravity;

        _velocity = DynamicsUtility.GetBallisticVelocity(endPosition, startPosition, angle, _gravity);

        Logger.Trace("Ballistic start velocity: " + _velocity + ", (startPosition: " + startPosition + ", endPosition: " + endPosition + ", gravity: " + gravity + ", angle: " + angle + ")");
    }