Ejemplo n.º 1
0
        private void PlayAnimations()
        {
            if (this.MovementComponent.Velocity != Vector2.Zero)
            {
                _animationTree.Set("parameters/Idle/blend_position", MovementComponent.Velocity);
                _animationTree.Set("parameters/Run/blend_position", MovementComponent.Velocity);
                _animationTree.Set("parameters/Attack1/blend_position", MovementComponent.Velocity);
            }

            switch (this._stateMachine.CurrentState?.Code)
            {
            case StatesIndex.Attack:
                _animationNodeStateMachinePlayback.Travel("Attack1");
                break;

            case StatesIndex.Idle:
                _animationNodeStateMachinePlayback.Travel("Idle");
                break;

            case StatesIndex.MoveForward:
                _animationNodeStateMachinePlayback.Travel("Run");
                break;

            default:
                _animationNodeStateMachinePlayback.Travel("Idle");
                break;
            }
        }
Ejemplo n.º 2
0
        private void HandleMovementState(float delta)
        {
            var inputVector = Vector2.Zero;

            inputVector.x = Input.GetActionStrength("ui_right") - Input.GetActionStrength("ui_left");
            inputVector.y = Input.GetActionStrength("ui_down") - Input.GetActionStrength("ui_up");
            inputVector.SetToNormalize();

            if (inputVector != Vector2.Zero)
            {
                SetWalkingStickKnockbackDirection(inputVector);
                _animationTree.Set("parameters/Idle/blend_position", inputVector);
                _animationTree.Set("parameters/Walk/blend_position", inputVector);
                _animationTree.Set("parameters/Attack/blend_position", inputVector);
                _animationState.Travel("Walk");
                _velocity = inputVector * _speed;
            }
            else
            {
                _animationState.Travel("Idle");
                _velocity = Vector2.Zero;
            }

            _velocity = MoveAndSlide(_velocity * delta);

            if (Input.IsActionJustPressed("attack"))
            {
                _state = PlayerState.Attack;
            }
        }
Ejemplo n.º 3
0
    //  // Called every frame. 'delta' is the elapsed time since the previous frame.
    //  public override void _Process(float delta)
    //  {
    //
    //  }
    public override void _PhysicsProcess(float delta)
    {
        Vector2 inputVector = Vector2.Zero;

        animationState = (AnimationNodeStateMachinePlayback)animationTree.Get("parameters/playback");

        inputVector.x = Input.GetActionStrength("ui_right") - Input.GetActionStrength("ui_left");
        inputVector.y = Input.GetActionStrength("ui_down") - Input.GetActionStrength("ui_up");
        inputVector   = inputVector.Normalized();

        if (inputVector != Vector2.Zero)
        {
            // Set animation tree blend position values based on inputVector value
            animationTree.Set("parameters/Idle/blend_position", inputVector);
            animationTree.Set("parameters/Run/blend_position", inputVector);

            animationState.Travel("Run");
            velocity = velocity.MoveToward(inputVector * MAX_SPEED, ACCELERATION * delta);
        }
        else
        {
            animationState.Travel("Idle");
            // Move
            velocity = velocity.MoveToward(Vector2.Zero, FRICTION * delta);
        }

        velocity = MoveAndSlide(velocity);
    }
Ejemplo n.º 4
0
    // runs every frame
    public override void _PhysicsProcess(float delta)
    {
        // player movement
        var inputVector = Vector2.Zero;

        // checks for direction
        inputVector.x = Input.GetActionStrength("move_right") - Input.GetActionStrength("move_left");
        inputVector.y = Input.GetActionStrength("move_down") - Input.GetActionStrength("move_up");

        // normalizes input to prevent double speed when two directions are entered
        inputVector = inputVector.Normalized();

        // set velocity of player
        if (inputVector != Vector2.Zero)
        {
            // running animation
            animationTree.Set("parameters/Idle/blend_position", inputVector);
            animationTree.Set("parameters/Run/blend_position", inputVector);
            animationState.Travel("Run");
            velocity = velocity.MoveToward(inputVector * MAX_SPEED, ACCELERATION * delta);
        }
        else
        {
            animationState.Travel("Idle");
            velocity = velocity.MoveToward(Vector2.Zero, FRICTION * delta);
        }



        velocity = MoveAndSlide(velocity);
    }
Ejemplo n.º 5
0
 // Called when physics
 public override void _PhysicsProcess(float delta)
 {
     if (STATE == 1)
     {
         // Begin accelerating in a specific direction
         animationTree.Set("parameters/Idle/blend_position", velocity);
         animationTree.Set("parameters/Run/blend_position", velocity);
         animationState.Travel("Run");
         velocity   = ((playerDetection.player as Player).GlobalPosition - GlobalPosition);
         velocity.y = 0;
         if (velocity.x > 10)
         {
             velocity.x = MAXSPEED;
         }
         else if (velocity.x < -10)
         {
             velocity.x = -MAXSPEED;
         }
         else
         {
             velocity.x = 0;
         }
         velocity = velocity.MoveToward(velocity * MAXSPEED, ACCELERATION * delta);
     }
     else if (playerDetection.player != null)
     {
         STATE = 1;
         audio.Play();
     }
     velocity = MoveAndSlide(velocity);
 }
Ejemplo n.º 6
0
    private void _MoveState(float delta)
    {
        // Get input from the user
        Vector2 InputVector = new Vector2();

        InputVector.x = Input.GetActionStrength("ui_right") - Input.GetActionStrength("ui_left");

        // gun stuff and mouse position
        gunNode.Visible         = false;
        gunNode.RotationDegrees = angle;
        if (angle > -90 && angle < 90)
        {
            gunNode.Scale = new Vector2(1, 1);
        }
        else
        {
            gunNode.Scale = new Vector2(1, -1);
        }

        if (InputVector != Vector2.Zero)
        {
            // Begin accelerating in a specific direction
            animationTree.Set("parameters/Idle/blend_position", InputVector);
            animationTree.Set("parameters/Run/blend_position", InputVector);
            animationState.Travel("Run");
            velocity = velocity.MoveToward(InputVector * MAXSPEED, ACCELERATION * delta);
            isWalking++;
        }
        else
        {
            // Begin slowing down
            animationState.Travel("Idle");
            velocity = velocity.MoveToward(Vector2.Zero, FRICTION * delta);
            walkTimer.Stop();
            isWalking = 0;
        }

        if (isWalking == 1)
        {
            walkTimer.Start();
        }

        // velocity = MoveAndSlideWithSnap(velocity, snapDist, snap, stopOnSlope: true);
        velocity = MoveAndSlide(velocity);

        if (Input.IsActionJustPressed("shoot") && ammo > 0)
        {
            EmitSignal(nameof(Shoot), bullet, gunNode.RotationDegrees, gunNode.GlobalPosition);
            state = Actions.SHOOT;
            ammo--;
            timer.Start();
        }

        if (Input.IsActionJustPressed("flash") && canFlash == true)
        {
            EmitSignal(nameof(Throw), flashbang, gunNode.RotationDegrees, gunNode.GlobalPosition);
            canFlash = false;
            flashCooldown.Start();
        }
    }
Ejemplo n.º 7
0
    private void RefreshAnimationConditions()
    {
        // Running Horizontally
        int  x             = GetXDirection();
        bool running_right = x > +0.1f;
        bool running_left  = x < -0.1f;
        bool running       = running_left || running_right;

        if (!Claw.LockDirection)
        {
            facingAnimation.Set("parameters/conditions/right", running_right);
            facingAnimation.Set("parameters/conditions/left", running_left);
        }
        moveAnimation.Set("parameters/conditions/running", running);
        moveAnimation.Set("parameters/conditions/not-running", !running);
        // On Ground
        bool grounded = IsOnGround && !Jumped;
        bool airborn  = !grounded && (Jumped || Math.Abs(Velocity.y) > 1);

        moveAnimation.Set("parameters/conditions/grounded", grounded);
        moveAnimation.Set("parameters/conditions/airborn", airborn);
        if (lastAirborn != airborn)
        {
            lastAirborn = airborn;
        }
        // Jump / Fall
        bool moving_down = Velocity.y > 0;

        moveAnimation.Set("parameters/airborn/conditions/up", !moving_down);
        moveAnimation.Set("parameters/airborn/conditions/down", moving_down);
    }
Ejemplo n.º 8
0
 public void setAnimationTree(Vector2 inputVector)
 {
     animationTree.Set("parameters/Idle/blend_position", inputVector);
     animationTree.Set("parameters/Run/blend_position", inputVector);
     animationTree.Set("parameters/Attack/blend_position", inputVector);
     animationTree.Set("parameters/Roll/blend_position", inputVector);
 }
Ejemplo n.º 9
0
    public override void _PhysicsProcess(float delta)
    {
        var         inputVector  = Vector2.Zero;
        const float acceleration = 200;
        const float maxSpeed     = 75;
        const float friction     = 250;

        base._PhysicsProcess(delta);
        inputVector.x = Input.GetActionStrength("ui_right") - Input.GetActionStrength("ui_left");
        inputVector.y = Input.GetActionStrength("ui_down") - Input.GetActionStrength("ui_up");
        inputVector   = inputVector.Normalized();

        if (inputVector != Vector2.Zero)
        {
            animationTree.Set("parameters/idle/blend_position", inputVector);
            animationTree.Set("parameters/walk/blend_position", inputVector);
            animationState.Travel("walk");
            velocity = velocity.MoveToward(inputVector * maxSpeed, acceleration * delta);
        }
        else
        {
            animationState.Travel("idle");
            velocity = velocity.MoveToward(Vector2.Zero, friction * delta);
        }

        velocity = MoveAndSlide(velocity);
    }
Ejemplo n.º 10
0
 private void SetAnimationDirection(Vector2 direction)
 {
     AnimationTree.Set("parameters/idle/blend_position", direction);
     AnimationTree.Set("parameters/walk/blend_position", direction);
     AnimationTree.Set("parameters/hurt/blend_position", direction);
     AnimationTree.Set("parameters/hit/blend_position", direction);
     AnimationTree.Set("parameters/die/blend_position", direction);
 }
Ejemplo n.º 11
0
        private Vector2 GetInput(float delta)
        {
            Vector2 inputVelocity = Vector2.Zero;

            if (!_sword.Swinging)
            {
                inputVelocity.x = Input.GetActionStrength("right") - Input.GetActionStrength("left");
                inputVelocity.y = Input.GetActionStrength("down") - Input.GetActionStrength("up");

                inputVelocity = inputVelocity.Normalized();
            }

            if (inputVelocity == Vector2.Zero)
            {
                _isMoving = false;
            }
            else
            {
                _isMoving = true;

                if (inputVelocity.Abs() != Vector2.One)
                {
                    _playerDirection = inputVelocity.Round();
                }
            }


            if (_isMoving)
            {
                _aTreePlayback.Travel("Running");
                _aTree.Set("parameters/AnimationNodeStateMachine/Idle/blend_position", inputVelocity);
                _aTree.Set("parameters/AnimationNodeStateMachine/Running/blend_position", inputVelocity);

                _currentSpeed += _acceleration * delta;

                if (_currentSpeed > _maxSpeed)
                {
                    _currentSpeed = _maxSpeed;
                }

                float animationSpeed = 1 + 2 * (_currentSpeed / _maxSpeed);

                _aTree.Set("parameters/TimeScale/scale", animationSpeed);

                return(_velocity.MoveToward(inputVelocity * _currentSpeed, _acceleration * delta));
            }

            _aTreePlayback.Travel("Idle");
            _aTree.Set("parameter/playback", "Idle");

            _currentSpeed = 0;

            return(_velocity.MoveToward(Vector2.Zero, _friction * delta));
        }
Ejemplo n.º 12
0
    private Vector2 GetInput(float delta)
    {
        Vector2 inputVelocity = Vector2.Zero;

        if (!_Sword.Swinging)
        {
            inputVelocity.x = Input.GetActionStrength("right") - Input.GetActionStrength("left");
            inputVelocity.y = Input.GetActionStrength("down") - Input.GetActionStrength("up");

            inputVelocity = inputVelocity.Normalized();
        }

        if (inputVelocity == Vector2.Zero)
        {
            IsMoving = false;
        }
        else
        {
            IsMoving = true;
        }


        if (IsMoving)
        {
            ATreePlayback.Travel("Running");
            ATree.Set("parameters/AnimationNodeStateMachine/Idle/blend_position", inputVelocity);
            ATree.Set("parameters/AnimationNodeStateMachine/Running/blend_position", inputVelocity);

            CurrentSpeed += Acceleration * delta;

            if (CurrentSpeed > MaxSpeed)
            {
                CurrentSpeed = MaxSpeed;
            }

            float animationSpeed = 1 + (2 * (CurrentSpeed / MaxSpeed));
            GD.Print(animationSpeed);

            ATree.Set("parameters/TimeScale/scale", animationSpeed);

            return(Velocity.MoveToward(inputVelocity * CurrentSpeed, (Acceleration * delta)));
        }
        else
        {
            ATreePlayback.Travel("Idle");
            ATree.Set("parameter/playback", "Idle");

            CurrentSpeed = 0;

            return(Velocity.MoveToward(Vector2.Zero, (Friction * delta)));
        }
    }
Ejemplo n.º 13
0
 public override void _Process(float delta)
 {
     if (attacking && !previousAttackCheck && spawned)
     {
         animTree.Set("parameters/TimeScale/scale", (float)(ANIMATION_SPEEDS.ATTACK_ANIM_SPEED * stats.attackSpeed));
         animTree.Set("parameters/State/current", ANIMATION_STATES.ATTACK);
         previousAttackCheck = true;
     }
 }
Ejemplo n.º 14
0
    private void setAnimState()
    {
        if (animation_state == ANIMATION_STATES.FALLING)
        {
            if ((ANIMATION_STATES)animTree.Get("parameters/State/current") != ANIMATION_STATES.WALK)
            {
                animTree.Set("parameters/Jumping/active", true);
            }

            animTree.Set("parameters/State/current", ANIMATION_STATES.FALLING);
        }
        else
        {
            if ((ANIMATION_STATES)animTree.Get("parameters/State/current") == ANIMATION_STATES.FALLING)
            {
                animTree.Set("parameters/HitGround/active", true);
            }

            if (animation_state == ANIMATION_STATES.ATTACK)
            {
                animTree.Set("parameters/State/current", ANIMATION_STATES.ATTACK);
            }
            else
            {
                animTree.Set("parameters/State/current", ANIMATION_STATES.WALK);
            }
        }
    }
 // Called when the node enters the scene tree for the first time.
 public override void _Ready()
 {
     _anim                  = GetNode <AnimationPlayer>("Anim");
     _animationTree         = GetNode <AnimationTree>("AnimationTree");
     _animationStateMachine = _animationTree.Get("parameters/StateMachine/playback") as AnimationNodeStateMachinePlayback;
     // _animationNodeTimeScale = _animationTree.Get("parameters/TimeScale/scale") as AnimationNodeTimeScale;
     _animationTree.Set("parameters/TimeScale/scale", 1 / MoveTime);
     _tween = GetNode <Tween>("Tween");
 }
Ejemplo n.º 16
0
 public override void _Process(float delta)
 {
     GetMovementInputValues();
     if (_Velocity.x != 0 || _Velocity.z != 0)
     {
         var AnimTreeBlend = Mathf.Lerp((float)PlayerAnimationsTree.Get("parameters/walkidle/blend_amount"), 1f, 0.07f);
         PlayerAnimationsTree.Set("parameters/walkidle/blend_amount", AnimTreeBlend);
     }
     else
     {
         var AnimTreeBlend = Mathf.Lerp((float)PlayerAnimationsTree.Get("parameters/walkidle/blend_amount"), 0f, 0.07f);
         PlayerAnimationsTree.Set("parameters/walkidle/blend_amount", AnimTreeBlend);
     }
     if (CanMove)
     {
         MoveAndSlide(_Velocity * _Movespeed, Vector3.Up, true);
     }
 }
Ejemplo n.º 17
0
        public override void _Process(float delta)
        {
            if (_player != null)
            {
                var direction = Position.DirectionTo(_player.Position);

                AnimationTree.Set("parameters/Run/blend_position", direction);
                AnimationTree.Set("parameters/Idle/blend_position", direction);
            }
        }
    public void OnTrajectoryUpdated(Vector3 translation, Vector3 velocity, Vector3 yaw, Vector3 pitch)
    {
        Translation = translation;
        Rotation    = yaw;
        var localVelocity = GlobalTransform.Inverse().basis.Xform(velocity);

        animTree.Set("parameters/locomotion/blend_position", new Vector2(localVelocity.x, localVelocity.z));

        //Pitch will be used when we have IK working with the model.
    }
Ejemplo n.º 19
0
    //As mentioned UpdateSpeak will recieve the delta
    private void UpdateSpeak(float delta)
    {
        //Find the first cue in the current delta
        var cue = speach.MouthCues.FirstOrDefault(x => x.Start <= delta && x.End >= delta);

        if (cue != default)
        {
            //Update the transition, we set the "current" parameter in our  Transition node
            animationTree.Set($"parameters/SpeakAnims/Transition/current", GetVisemeValue(cue.Value));
        }
    }
Ejemplo n.º 20
0
Archivo: Player.cs Proyecto: itlbv/evo
    public override void _PhysicsProcess(float delta)
    {
        var velocity = Vector2.Zero;

        velocity.x = Input.GetActionStrength("ui_right") - Input.GetActionStrength("ui_left");
        velocity.y = Input.GetActionStrength("ui_down") - Input.GetActionStrength("ui_up");
        velocity   = velocity.Normalized();

        if (velocity != Vector2.Zero)
        {
            animationTree.Set("parameters/idle/blend_position", velocity);
            animationTree.Set("parameters/walk/blend_position", velocity);
            animationState.Travel("walk");
        }
        else
        {
            animationState.Travel("idle");
        }

        MoveAndSlide(velocity * speed);
    }
Ejemplo n.º 21
0
    private void _MoveState(float delta)
    {
        Vector2 InputVector = new Vector2();

        InputVector.x = Input.GetActionStrength("ui_right") - Input.GetActionStrength("ui_left");

        if (InputVector != Vector2.Zero)
        {
            // Begin accelerating in a specific direction
            animationTree.Set("parameters/Idle/blend_position", InputVector);
            animationTree.Set("parameters/Walk/blend_position", InputVector);
            animationState.Travel("Walk");
            velocity = velocity.MoveToward(InputVector * MAXSPEED, ACCELERATION * delta);
        }
        else
        {
            // Begin slowing down
            animationState.Travel("Idle");
            velocity = velocity.MoveToward(Vector2.Zero, FRICTION * delta);
        }
    }
Ejemplo n.º 22
0
    // Called every frame. 'delta' is the elapsed time since the previous frame.
    public override void _PhysicsProcess(float delta)
    {
        Vector2 inputDirection = Vector2.Zero;
        Boolean inputMagnitude = false;

        mousePos = GetLocalMousePosition();



        inputDirection.x = Input.GetActionStrength("ui_right") - Input.GetActionStrength("ui_left");
        inputDirection.y = Input.GetActionStrength("ui_down") - Input.GetActionStrength("ui_up");
        inputDirection   = inputDirection.Normalized();
        if (inputDirection != Vector2.Zero)
        {
            inputMagnitude = true;
        }
        else
        {
            inputMagnitude = false;
        }

        if (inputMagnitude)
        {
            velocity = velocity.MoveToward(inputDirection * maxSpeed, acceleration * delta);
            animatorTree.Set("parameters/Run/blend_position", mousePos);


            animatorState.Travel("Run");
        }
        else
        {
            velocity = velocity.MoveToward(Vector2.Zero, friction * delta);
            animatorTree.Set("parameters/Idle/blend_position", mousePos);
            animatorState.Travel("Idle");
        }
        velocity = MoveAndSlide(velocity);
    }
Ejemplo n.º 23
0
    // Called every frame. 'delta' is the elapsed time since the previous frame.
    public override void _Process(float delta)
    {
        Vector2 input_vector = Vector2.Zero;

        input_vector.x = Input.GetActionStrength("ui_right") - Input.GetActionStrength("ui_left");
        input_vector.y = Input.GetActionStrength("ui_down") - Input.GetActionStrength("ui_up");
        input_vector   = input_vector.Normalized();

        if (input_vector != Vector2.Zero)
        {
            animationTree.Set("parameters/Idle/blend_position", input_vector);
            animationTree.Set("parameters/Run/blend_position", input_vector);
            animationState.Travel("Run");

            velocity = velocity.MoveToward(input_vector * MaxSpeed, Acceleration * delta);
        }
        else
        {
            animationState.Travel("Idle");
            velocity = velocity.MoveToward(Vector2.Zero, Friction * delta);
        }

        velocity = MoveAndSlide(velocity);
    }
Ejemplo n.º 24
0
    public override void _Process(float delta)
    {
        _horizontalInput = Input.GetActionStrength("move_right") - Input.GetActionStrength("move_left");

        if (Input.IsActionJustPressed("jump"))
        {
            _jumpBuffer = true;
        }

        _animTree.Set("parameters/movement/current", _cc.GetHorizontalVelocity != 0f);

        if (_cc.GetVelocity.x != 0f)
        {
            _sprite.FlipH = _cc.GetVelocity.x < 0f;
        }
    }
Ejemplo n.º 25
0
        private void MoveAlongPath(float delta)
        {
            if (_path != null && _path.Count > 0)
            {
                float moveDistance = _speed * delta;

                while (moveDistance > 0 && _path.Count > 0)
                {
                    var distanceToNextPoint = Position.DistanceTo(_path[0]);
                    var direction           = Position.DirectionTo(_path[0]);

                    AnimationTree.Set("parameters/Run/blend_position", direction);
                    AnimationTree.Set("parameters/Idle/blend_position", direction);
                    AnimationMode.Travel("Run");

                    if (moveDistance <= distanceToNextPoint)
                    {
                        var velocity = MoveAndSlide(direction * _speed);

                        if (GetSlideCount() > 0)
                        {
                            var collision = GetSlideCollision(0);

                            if (collision != null)
                            {
                                if (velocity.Length() < 20)
                                {
                                    _path.Clear();
                                }
                            }
                        }
                    }
                    else
                    {
                        Position = _path[0];
                        _path.RemoveAt(0);
                    }

                    moveDistance -= distanceToNextPoint;
                }
            }
            else
            {
                AnimationMode.Travel("Idle");
            }
        }
Ejemplo n.º 26
0
 public override void _Process(float delta)
 {
     if (time > 0 && loaded)
     {
         if (time < 2)
         {
             tree.Set("parameters/conditions/Hit", false);
         }
         time -= delta;
         if (time < 0)
         {
             close = true;
         }
     }
     if (close)
     {
         if (PlayerController.Instance.GlobalTransform.origin.DistanceTo(GlobalTransform.origin) > 5)
         {
             tree.Set("parameters/conditions/Time", true);
         }
     }
 }
Ejemplo n.º 27
0
    void MoveState(float delta)
    {
        Vector2 input_vector = Vector2.Zero;

        input_vector.x = Input.GetActionStrength("ui_right") - Input.GetActionStrength("ui_left");
        input_vector.y = Input.GetActionStrength("ui_down") - Input.GetActionStrength("ui_up");
        input_vector   = input_vector.Normalized();

        if (input_vector != Vector2.Zero)
        {
            rollVector = input_vector;
            animTree.Set("parameters/Idle/blend_position", lookDirection);
            animTree.Set("parameters/Run/blend_position", lookDirection);
            animTree.Set("parameters/Attack/blend_position", lookDirection);
            animTree.Set("parameters/Roll/blend_position", lookDirection);
            animState.Travel("Run");
            velocity = input_vector * maxSpeed;
        }
        else
        {
            rollVector = lookDirection;
            animState.Travel("Idle");
            animTree.Set("parameters/Idle/blend_position", lookDirection);
            animTree.Set("parameters/Attack/blend_position", lookDirection);
            animTree.Set("parameters/Roll/blend_position", lookDirection);
            velocity = Vector2.Zero;
        }

        Move();

        if (Input.IsActionJustPressed("attack"))
        {
            state = AnimationState.ATTACK;
        }
        if (Input.IsActionJustPressed("roll"))
        {
            state = AnimationState.ROLL;
        }
    }
Ejemplo n.º 28
0
 public void Animate(Vector3 vel)
 {
     AnimTree.Set("parameters/Idle_Walk/Idle_Walk/blend_position", new Vector2(vel.z, vel.x));
 }
Ejemplo n.º 29
0
    protected virtual void ProcessInput(float delta)
    {
        //  ----------------------- Jumping -----------------------
        if (!_jumping && Input.IsActionJustPressed("movement_jump"))
        {
            _animationTree.Set("parameters/jump_os/active", true);
            _jumping = true;
        }

        //  ----------------------- Walking -----------------------
        Vector2 inputMovementVector = new Vector2();

        if (Input.IsActionPressed("movement_forward") && !_lockZMovement)
        {
            inputMovementVector.y += 1;
        }
        if (Input.IsActionPressed("movement_backward") && !_lockZMovement)
        {
            inputMovementVector.y += -1;
        }
        if (Input.IsActionPressed("movement_left") && !_lockXMovement)
        {
            inputMovementVector.x += 1;
        }
        if (Input.IsActionPressed("movement_right") && !_lockXMovement)
        {
            inputMovementVector.x += -1;
        }

        // if you're jumping ignore directional input
        if (!_jumping)
        {
            // set running animation
            _animationTree.Set("parameters/run_bs2d/blend_position", inputMovementVector);
            inputMovementVector = inputMovementVector.Normalized();
        }
        else
        {
            inputMovementVector = Vector2.Zero;
        }
        // convert local movement vectors to global movement vectors
        _dir  = Vector3.Zero;
        _dir += GlobalTransform.basis.x * inputMovementVector.x;
        _dir += GlobalTransform.basis.z * inputMovementVector.y;

        //  ----------------------- Sprinting -----------------------
        _isSprinting = Input.IsActionPressed("movement_sprint") && !_jumping;

        // -------------- Capturing/Freeing the cursor --------------
        if (Input.IsActionJustPressed("ui_cancel"))
        {
            if (Input.GetMouseMode() == Input.MouseMode.Visible)
            {
                Input.SetMouseMode(Input.MouseMode.Captured);
            }
            else
            {
                Input.SetMouseMode(Input.MouseMode.Visible);
            }
        }
        // ---------------- Change Camera for Debug ----------------
        if (Input.IsActionJustPressed("debug_swap_camera"))
        {
            if (_camera.Current)
            {
                _debugCamera.Current = true;
            }
            else if (_debugCamera.Current)
            {
                _camera.Current = true;
            }
        }
    }
Ejemplo n.º 30
0
 public void setMoveDirection(Vector3 direction)
 {
     moveDirection = direction;
     animationTree.Set("parameters/move_ground/blend_position", direction.Length());
 }