示例#1
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);
            }
        }
    }
示例#2
0
文件: Player.cs 项目: ugdt/zelcrawler
 public override void _Ready()
 {
     _aTree         = GetNode <AnimationTree>("AnimationTree");
     _sword         = GetNode <Sword>("Sword");
     _aTreePlayback =
         (AnimationNodeStateMachinePlayback)_aTree.Get("parameters/AnimationNodeStateMachine/playback");
 }
示例#3
0
 // Called when the node enters the scene tree for the first time.
 public override void _Ready()
 {
     animator            = GetNode <AnimationPlayer>("Animation");
     animatorTree        = GetNode <AnimationTree>("AnimationTree");
     animatorState       = (AnimationNodeStateMachinePlayback)animatorTree.Get("parameters/playback");
     animatorTree.Active = true;
 }
示例#4
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);
    }
示例#5
0
 public override void _Ready()
 {
     base._Ready();
     _animationTree = (AnimationTree)GetNodeOrNull("AnimationTree");
     _stateMachine  = (AnimationNodeStateMachinePlayback)_animationTree.Get("parameters/playback");
     AddFloatDelegate(MouseFollowerDelegateManager.Group.BLINK_SPEED_MODIFIER, ModifyBlinkSpeed);
 }
示例#6
0
 // Called when the node enters the scene tree for the first time.
 public override void _Ready()
 {
     _animTree        = GetNode <AnimationTree>("AnimationTree");
     _animTree.Active = true;
     stateMachine     = (AnimationNodeStateMachinePlayback)_animTree.Get("parameters/StateMachine/playback");
     state            = new AmandaIdle(this);
     fallingTimer     = GetNode <Timer>("FallingTimer");
 }
示例#7
0
 public override void _Ready()
 {
     _AnimationTree        = GetNode <AnimationTree>("AnimationTree");
     _AnimationTree.Active = true;
     StateMachineArms      = (AnimationNodeStateMachinePlayback)_AnimationTree.Get("parameters/StateMachine/playback");
     Walk = 0f;
     Jump = Land = Fall = Retract = false;
 }
示例#8
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);
     }
 }
 // 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");
 }
示例#10
0
    public override void _Ready()
    {
        playerStats = (Stats)GetNode("/root/PlayerStats");
        playerStats.Connect("NoHealth", this, "queue_free");
        blinkAnimationPlayer = (AnimationPlayer)GetNode("BlinkAnimationPlayer");
        animationTree        = (AnimationTree)GetNode("AnimationTree");
        animationTree.Active = true;
        playerAnimationState = (AnimationNodeStateMachinePlayback)animationTree.Get("parameters/playback");

        //These pins are added to the player inventory temporarily for testing. They will be removed later.
        (string abilityAddress, string userAnimation, bool passive) = AbilityCatalog.SwordSwipe();
        PlayerPins.Add(new Pin {
            AbilityAddress = abilityAddress,
            UserAnimation  = userAnimation,
            Passive        = passive,
            Level          = 1,
            EXP            = 0,
            Quality        = 0,
            SlotNum        = 1
        });

        (abilityAddress, userAnimation, passive) = AbilityCatalog.Fireball();
        PlayerPins.Add(new Pin {
            AbilityAddress = abilityAddress,
            UserAnimation  = userAnimation,
            Passive        = passive,
            Level          = 1,
            EXP            = 0,
            Quality        = 0,
            SlotNum        = 2
        });

        (abilityAddress, userAnimation, passive) = AbilityCatalog.Thing();
        PlayerPins.Add(new Pin {
            AbilityAddress = abilityAddress,
            UserAnimation  = userAnimation,
            Passive        = passive,
            Level          = 1,
            EXP            = 0,
            Quality        = 0,
            SlotNum        = 3
        });

        (abilityAddress, userAnimation, passive) = AbilityCatalog.StandHeal();
        PlayerPins.Add(new Pin {
            AbilityAddress = abilityAddress,
            UserAnimation  = userAnimation,
            Passive        = passive,
            Level          = 1,
            EXP            = 0,
            Quality        = 0,
            SlotNum        = 6
        });

        SlotSets = BuildSlotSets(PlayerPins);
        LoadAbilities(SlotSets[currentSlotSet]);
    }
示例#11
0
 // Called when the node enters the scene tree for the first time.
 public override void _Ready()
 {
     _playerSprite         = GetNode <Sprite>("Sprite");
     _animationPlayer      = GetNode <AnimationPlayer>("AnimationPlayer");
     _animationTree        = GetNode <AnimationTree>("AnimationTree");
     _stateMachine         = (AnimationNodeStateMachinePlayback)_animationTree.Get("parameters/playback");
     _animationTree.Active = true;
     _stateMachine.Start("idle");
 }
 public override void _Ready()
 {
     animationTree        = (AnimationTree)GetNode("AnimationTree");
     animationTree.Active = true;
     animationState       = (AnimationNodeStateMachinePlayback)animationTree.Get("parameters/playback");
     hitbox = (HitboxSword)GetNode("HitboxPivot/HitboxSword");
     hitbox.KnockbackVector = KnockbackVector * KnockbackPower;
     hitbox.Damage          = AttackPower;
 }
示例#13
0
    int HEALTH = 3 + 1; // idk why he takes damage instantly when spawning

    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {
        audio                = GetNode <AudioStreamPlayer>("AudioStreamPlayer");
        audio.VolumeDb       = 3;
        animationPlayer      = GetNode <AnimationPlayer>("AnimationPlayer");
        animationTree        = GetNode <AnimationTree>("AnimationTree");
        animationTree.Active = true;
        animationState       = animationTree.Get("parameters/playback") as AnimationNodeStateMachinePlayback;
        playerDetection      = GetNode <Area2D>("PlayerDetection") as PlayerDetection;
    }
示例#14
0
    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {
        Anim             = GetNode <AnimationPlayer>("AnimationPlayer");
        AnimTree         = GetNode <AnimationTree>("AnimationTree");
        AnimStateMachine = AnimTree.Get("parameters/playback") as AnimationNodeStateMachinePlayback;
        AnimTree.Active  = true;

        Game = GetTree().Root.GetNode <Game>("Game");
        // GroundMap = Game.GetNode<TileMap>("Ground");
        // RayCastAStar = new RayCastAStar(GroundMap, GetWorld2d().DirectSpaceState);
    }
示例#15
0
文件: Animation.cs 项目: wsenh/ld47
        public override void _Ready()
        {
            base._Ready();

            Player         = GetNode <Player>("../..");
            AnimatedSprite = GetNode <AnimatedSprite>("../../AnimatedSprite");
            AnimationTree  = GetNode <AnimationTree>("../../AnimationTree");
            StateMachine   = AnimationTree.Get("parameters/playback") as AnimationNodeStateMachinePlayback;

            AnimatedSprite.Play();
        }
示例#16
0
    public override void _Ready()
    {
        base._Ready();

        body2D = this as KinematicBody2D;

        sprite            = GetNode("Sprite") as Sprite;
        animationPlayer   = GetNode("AnimationPlayer") as AnimationPlayer;
        animationTree     = GetNode("AnimationTree") as AnimationTree;
        animationPlayback = animationTree.Get("parameters/playback") as AnimationNodeStateMachinePlayback;
        animationPlayback.Start("idle");
    }
示例#17
0
    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {
        playerStats = (Stats)GetNode("/root/PlayerStats");
        playerStats.Connect("noHitpoints", this, "_onNoHitPoints");

        rollCdTimer          = ROLL_COOLDOWN;
        swordHitbox          = GetNode <SwordHitbox>("HitboxPivot/SwordHitbox");
        hurtbox              = GetNode <Hurtbox>("Hurtbox");
        animationPlayer      = GetNode <AnimationPlayer>("AnimationPlayer");
        blinkAnimationPlayer = GetNode <AnimationPlayer>("BlinkAnimationPlayer");
        animationTree        = GetNode <AnimationTree>("AnimationTree");
        animationTree.Active = true;
        animationState       = animationTree.Get("parameters/playback") as AnimationNodeStateMachinePlayback;
    }
示例#18
0
        public override void _Ready()
        {
            _stats = GetNode <Stats>("PlayerStats");
            _stats.Connect("NoHealth", this, nameof(Death));

            _animationTree        = GetNode <AnimationTree>("AnimationTree");
            _animationState       = (AnimationNodeStateMachinePlayback)_animationTree.Get("parameters/playback");
            _animationTree.Active = true;
            _blinkAnimationPlayer = GetNode <AnimationPlayer>("BlinkAnimationPlayer");

            _hurtBox = GetNode <HurtBox>("HurtBox");

            _walkingStickHitBox = GetNode <WalkingStick>("HitboxPivot/WalkingStickHitBox");
        }
示例#19
0
 // Called when the node enters the scene tree for the first time.
 public override void _Ready()
 {
     animationPlayer      = GetNode <AnimationPlayer>("AnimationPlayer");
     animationTree        = GetNode <AnimationTree>("AnimationTree");
     gunNode              = GetNode <Node2D>("Gun");
     animationTree.Active = true;
     animationState       = animationTree.Get("parameters/playback") as AnimationNodeStateMachinePlayback;
     bullet        = GD.Load <PackedScene>("res://Player/Bullet.tscn");
     flashbang     = GD.Load <PackedScene>("res://Player/Flashbang.tscn");
     timer         = GetNode <Timer>("Timer");
     flashCooldown = GetNode <Timer>("FlashCooldown");
     walkTimer     = GetNode <Timer>("WalkTimer");
     sound         = GetNode <AudioStreamPlayer>("AudioStreamPlayer");
 }
示例#20
0
文件: Animation.cs 项目: itlbv/evo
    public override void _Ready()
    {
        OwnerMob = (Mob)Owner;

        Actions = OwnerMob.Actions;

        AnimationTree  = OwnerMob.GetNode <AnimationTree>("Animation/AnimationTree");
        AnimationState = AnimationTree.Get("parameters/playback") as AnimationNodeStateMachinePlayback;

        HurtAnimationDelayTimer          = new Timer();
        HurtAnimationDelayTimer.Name     = "HurtAnimationDelayTimer";
        HurtAnimationDelayTimer.WaitTime = 0.2f;
        AddChild(HurtAnimationDelayTimer);
    }
示例#21
0
    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {
        playerStats = GetNode <Stats>("/root/PlayerStats");
        playerStats.OnZeroHealth += Die;

        hurtbox = GetNode <Hurtbox>("Hurtbox");
        hurtbox.OnInvincibilityStarted += BlinkStart;
        hurtbox.OnInvincibilityEnded   += BlinkStop;

        animPlayer      = GetNode <AnimationPlayer>("AnimationPlayer");
        animTree        = GetNode <AnimationTree>("AnimationTree");
        animState       = (AnimationNodeStateMachinePlayback)animTree.Get("parameters/playback");
        animTree.Active = true;

        blinkAnimationPlayer = GetNode <AnimationPlayer>("BlinkAnimationPlayer");
    }
示例#22
0
    public void Init()
    {
        Bow    = (Spatial)GetNode("Skeleton/LeftHandAttachment/Bow");
        Arrow  = (Spatial)GetNode("Skeleton/RightHandAttachment/Arrow");
        Pistol = (Spatial)GetNode("Skeleton/RightHandAttachment/Pistol");

        PunchArea          = (Area)GetNode("Skeleton/RightHandAttachment/Area");
        BodyCollisionShape = (CollisionShape)GetNode("CollisionShape");
        BulletRay          = (RayCast)GetNode("BulletRayCast");

        AnimTree     = (AnimationTree)GetNode("AnimationTree");
        StateMachine = (AnimationNodeStateMachinePlayback)AnimTree.Get("parameters/playback");
        ChangeState(State);

        //LeftFootRayCast = (RayCast)GetNode("Skeleton/LeftFootAttachment/RayCast");
        //RightFootRayCast = (RayCast)GetNode("Skeleton/RightFootAttachment/RayCast");
    }
示例#23
0
    public override void _Ready()
    {
        _AnimationPlayer     = GetNode <AnimationPlayer>("AnimationPlayer");
        _Sprite              = GetNode <Sprite>("Sprite");
        _AnimationTree       = GetNode <AnimationTree>("AnimationTree");
        _YeetedCatDelayTimer = GetNode <Timer>("YeetedCatDelayTimer");

        _AnimStateMachine = (AnimationNodeStateMachinePlayback)
                            _AnimationTree.Get("parameters/playback");

        _RightWallRaycasts = GetNode <Node2D>("RightWallRaycasts");
        _LeftWallRaycasts  = GetNode <Node2D>("LeftWallRaycasts");

        _YeetedCatPrefab = (PackedScene)GD.Load("res://Scenes/YeetedCat.tscn");

        _Hud = GetNode <HUD>("HUD");

        _AudioStreamPlayer = GetNode <AudioStreamPlayer>("AudioStreamPlayer");
    }
示例#24
0
    public override void _Ready()
    {
        base._Ready();

        jumpGravity      = 2.0f * jumpHeight / Mathf.Pow(jumpDuration / 2.0f, 2);
        fallGravity      = 2.0f * jumpHeight / Mathf.Pow(fallDuration / 2.0f, 2);
        jumpSpeed        = -Mathf.Sqrt(2.0f * jumpGravity * jumpHeight);
        terminalVelocity = airborneTerminalVelocity;

        sprite          = GetNode("Sprite") as Sprite;
        animationPlayer = GetNode("AnimationPlayer") as AnimationPlayer;
        animationTree   = GetNode("AnimationTree") as AnimationTree;
        animationTree.SetActive(true);
        animationPlayback = animationTree.Get("parameters/playback") as AnimationNodeStateMachinePlayback;
        animationPlayback.Start("stand");

        hitbox = GetNode("Sprite/Hitbox") as Area2D;
        hitbox.Connect("area_entered", this, "_On_Hitbox_AreaEntered");
    }
    public override void _Ready()
    {
        moveDirection = Vector3.Zero;

        animationTree = GetNode <AnimationTree>("AnimationTree");
        if (animationTree == null)
        {
            GD.PushError("AnimationTree reference is null!");
        }
        else
        {
            animationTree.Active = true;
            playback             = animationTree.Get("parameters/playback") as AnimationNodeStateMachinePlayback;
        }
        animationPlayer = GetNode <AnimationPlayer>("AnimationPlayer");
        if (animationPlayer == null)
        {
            GD.PushError("AnimationPlayer reference is null!");
        }
    }
        public override void _PhysicsProcess(float delta)
        {
            if (_test_shoot)
            {
                Shoot();
                _test_shoot = false;
            }

            if (_dead)
            {
                return;
            }

            if (_player == null)
            {
                _animationTree.Set("arameters/state/current", 0); //Go idle.
                return;
            }

            if (_state == StateEnum.Approach)
            {
                if (_aimPreparing > 0.0)
                {
                    _aimPreparing -= delta;
                    if (_aimPreparing < 0.0)
                    {
                        _aimPreparing = 0;
                    }
                    _animationTree.Set("parameters/aiming/blend_amount", _aimPreparing / AimPrepareTime);
                }

                var toPlayerLocal = GlobalTransform.XformInv(_player.GlobalTransform.origin);
                // The front of the robot is +Z, and atan2 is zero at +X, so we need to use the Z for the X parameter (second one).
                var angleToPlayer = Mathf.Atan2(toPlayerLocal.x, toPlayerLocal.z);
                var tolerance     = Mathf.Deg2Rad(PlayerAimToleranceDegrees);
                if (angleToPlayer > tolerance)
                {
                    _animationTree.Set("parameters/state/current", 1);
                }
                else if (angleToPlayer < -tolerance)
                {
                    _animationTree.Set("parameters/state/current", 2);
                }
                else
                {
                    _animationTree.Set("parameters/state/current", 3);
                    // Facing player, try to shoot.

                    _shootCountdown -= delta;
                    if (_shootCountdown < 0.0)
                    {
                        // See if player can be killed because in they're sight.
                        var rayOrigin = _rayFrom.GlobalTransform.origin;
                        var rayTo     = _player.GlobalTransform.origin + Vector3.Up; // Above middle of player.
                        var col       = GetWorld().DirectSpaceState.IntersectRay(rayOrigin, rayTo, new Godot.Collections.Array()
                        {
                            this
                        });
                        if (col.Count > 0 && col["collider"] is PlayerEntity)
                        {
                            _state        = StateEnum.Aim;
                            _aimCountdown = AimTime;
                            _aimPreparing = 0;
                            _animationTree.Set("parameters/state/current", 0);
                        }
                        else
                        {
                            _shootCountdown = ShootWait;
                        }
                    }
                }
            }
            else if (_state == StateEnum.Aim || _state == StateEnum.Shooting)
            {
                if (_aimPreparing < AimPrepareTime)
                {
                    _aimPreparing += delta;
                    if (_aimPreparing > AimPrepareTime)
                    {
                        _aimPreparing = AimPrepareTime;
                    }
                }

                _animationTree.Set("parameters/aiming/blend_amount", Mathf.Clamp(_aimPreparing / AimPrepareTime, 0, 1));
                _aimCountdown -= delta;
                if (_aimCountdown < 0 && _state == StateEnum.Aim)
                {
                    var rayOrigin = _rayFrom.GlobalTransform.origin;
                    var rayTo     = _player.GlobalTransform.origin + Vector3.Up; // Above middle of player.
                    var col       = GetWorld().DirectSpaceState.IntersectRay(rayOrigin, rayTo, new Godot.Collections.Array()
                    {
                        this
                    });
                    if (col.Count > 0 && col["collider"] is PlayerEntity)
                    {
                        _state = StateEnum.Shooting;
                        _shootAnimation.Play("shoot");
                    }
                    else
                    {
                        ResumeApproach();
                    }
                }

                if (_animationTree.Active)
                {
                    var toCannonLocal = _rayMesh.GlobalTransform.XformInv(_player.GlobalTransform.origin + Vector3.Up);
                    var hAngle        = Mathf.Rad2Deg(Mathf.Atan2(toCannonLocal.x, -toCannonLocal.z));
                    var vAngle        = Mathf.Rad2Deg(Mathf.Atan2(toCannonLocal.y, -toCannonLocal.z));

                    var blendPos = (Vector2)_animationTree.Get("parameters/aim/blend_position");
                    var hMotion  = BlendAimSpeed * delta * -hAngle;
                    blendPos.x += hMotion;
                    blendPos.x  = Mathf.Clamp(blendPos.x, -1, 1);

                    var vMotion = BlendAimSpeed * delta * vAngle;
                    blendPos.y += vMotion;
                    blendPos.y  = Mathf.Clamp(blendPos.y, -1, 1);

                    _animationTree.Set("parameters/aim/blend_position", blendPos);
                }
            }

            _orientation *= _animationTree.GetRootMotionTransform();

            var hVelocity = _orientation.origin / delta;

            _velocity.x = hVelocity.x;
            _velocity.z = hVelocity.z;
            _velocity  += _gravity * delta;
            _velocity   = MoveAndSlide(_velocity, Vector3.Up);

            _orientation.origin = new Vector3();
            _orientation        = _orientation.Orthonormalized();

            var gt = GlobalTransform;

            gt.basis        = _orientation.basis;
            GlobalTransform = gt;
        }
示例#27
0
 // runs on load
 public override void _Ready()
 {
     animationTree  = GetNode <AnimationTree>("AnimationTree");
     animationState = (AnimationNodeStateMachinePlayback)animationTree.Get("parameters/playback");
 }
示例#28
0
文件: Player.cs 项目: itlbv/evo
 public override void _Ready()
 {
     animationPlayer = GetNode <AnimationPlayer>("Animation/AnimationPlayer");
     animationTree   = GetNode <AnimationTree>("Animation/AnimationTree");
     animationState  = animationTree.Get("parameters/playback") as AnimationNodeStateMachinePlayback;
 }
示例#29
0
    public override void _PhysicsProcess(float delta)
    {
        if (!spawned)
        {
            return;
        }

        falling = !IsOnFloor();
        if (falling && !wasFalling)
        {
            wasFalling = true;
        }

        var motion_target = new Vector2(
            Input.GetActionStrength("move_right") - Input.GetActionStrength("move_left"),
            Input.GetActionStrength("move_forward") - Input.GetActionStrength("move_back")
            );

        motion = motion.LinearInterpolate(motion_target, MotionInterpolateSpeed * delta);

        // Camera rotation stuff
        var cam_z = camera.GlobalTransform.basis.z;
        var cam_x = -camera.GlobalTransform.basis.x;

        cam_z.y = 0;
        cam_z   = cam_z.Normalized();
        cam_x.y = 0;
        cam_x   = cam_x.Normalized();

        if (falling)
        {
            animTree.Set("parameters/State/current", ANIMATION_STATES.FALLING);
            ApplyRotationBasedOnMovement(cam_x, cam_z, delta);
        }
        else
        {
            if (!attacking)
            {
                animTree.Set("parameters/State/current", ANIMATION_STATES.WALK);
                ApplyRotationBasedOnMovement(cam_x, cam_z, delta);
            }
            else
            {
                ApplyRotationBasedOnMovement(cam_x, cam_z, delta);
            }
        }

        // Movement
        if (motion_target.x != 0 || motion_target.y != 0)
        {
            currentBlendPosition += .1f;
            currentAnimTimeScale  = stats.movementSpeed * ANIMATION_SPEEDS.WALK_ANIM_SPEED;
            velocity             += mesh.Transform.basis.z;
        }
        else
        {
            currentAnimTimeScale  = 1f;
            currentBlendPosition -= .1f;
        }

        if (!falling && !attacking)
        {
            if (Input.IsKeyPressed(Keybinds.KEYBIND_JUMP) && timeLeftToStartJump <= 0)
            {
                timeLeftToStopJumpForce = JumpTime;
                timeLeftToStartJump     = WaitTimeBeforeJump;
                animTree.Set("parameters/Jumping/active", true);
            }
        }

        if (timeLeftToStopJumpForce > 0)
        {
            if (timeLeftToStartJump > 0)
            {
                timeLeftToStartJump--;
            }
            else
            {
                velocity.y += JumpSpeedStep;
                timeLeftToStopJumpForce--;
            }
        }

        if (wasFalling && !falling)
        {
            animTree.Set("parameters/HitGround/active", true);
            wasFalling = false;
        }

        currentBlendPosition = Mathf.Clamp(currentBlendPosition, -1f, 1f);
        velocity            += Gravity * delta;
        velocity            *= (float)(stats.movementSpeed * ANIMATION_SPEEDS.WALK_SPEED_MODIFIER); // Mov speed
        if (!attacking)
        {
            velocity = MoveAndSlide(velocity, new Vector3(0, 1, 0), true, 1);
        }
        velocity = Vector3.Zero;

        orientation          = orientation.Orthonormalized();
        mesh.GlobalTransform = new Transform(orientation.basis, mesh.GlobalTransform.origin);

        if (falling)
        {
            animTree.Set("parameters/TimeScale/scale", ANIMATION_SPEEDS.PLAYER_FALLING_ANIM_SPEED);
        }
        else
        {
            animTree.Set("parameters/Walk/blend_position", currentBlendPosition);
            if (!attacking)
            {
                animTree.Set("parameters/TimeScale/scale", currentAnimTimeScale);
            }
        }

        data.animation_state = (ANIMATION_STATES)animTree.Get("parameters/State/current");
        data.heading         = Mathf.FloorToInt(this.mesh.RotationDegrees.y);
        data.pos             = new System.Numerics.Vector3(
            Transform.origin.x.ToString("0.000").ToFloat(),
            Transform.origin.y.ToString("0.000").ToFloat(),
            Transform.origin.z.ToString("0.000").ToFloat());
    }
示例#30
0
 public override void _Ready()
 {
     AnimationTree = GetNode <AnimationTree>("AnimationTree");
     AnimationMode = (AnimationNodeStateMachinePlayback)AnimationTree.Get("parameters/playback");
     _navigation2D = GetNode <Navigation2D>("/root/Map/Game/Navigation2D");
 }