diff --git a/DungeonShooting_Godot/prefab/role/Player.tscn b/DungeonShooting_Godot/prefab/role/Player.tscn index cfc566b..bf3afb0 100644 --- a/DungeonShooting_Godot/prefab/role/Player.tscn +++ b/DungeonShooting_Godot/prefab/role/Player.tscn @@ -16,4 +16,4 @@ material = SubResource( 1 ) [node name="AnimatedSprite" parent="." index="2"] -frame = 2 +frame = 1 diff --git a/DungeonShooting_Godot/prefab/role/Role.tscn b/DungeonShooting_Godot/prefab/role/Role.tscn index 7b06e6f..45897d9 100644 --- a/DungeonShooting_Godot/prefab/role/Role.tscn +++ b/DungeonShooting_Godot/prefab/role/Role.tscn @@ -91,7 +91,6 @@ position = Vector2( 0, -12 ) frames = SubResource( 6 ) animation = "idle" -frame = 3 playing = true [node name="Collision" type="CollisionShape2D" parent="."] diff --git a/DungeonShooting_Godot/project.godot b/DungeonShooting_Godot/project.godot index 67e6968..fcefc81 100644 --- a/DungeonShooting_Godot/project.godot +++ b/DungeonShooting_Godot/project.godot @@ -175,7 +175,9 @@ [physics] +common/physics_jitter_fix=0.0 common/enable_pause_aware_picking=true +common/physics_interpolation=true [rendering] diff --git a/DungeonShooting_Godot/src/game/camera/MainCamera.cs b/DungeonShooting_Godot/src/game/camera/MainCamera.cs index 71cf8ac..f8170f8 100644 --- a/DungeonShooting_Godot/src/game/camera/MainCamera.cs +++ b/DungeonShooting_Godot/src/game/camera/MainCamera.cs @@ -25,14 +25,14 @@ private Vector2 _camPos; private Vector2 _shakeOffset = Vector2.Zero; - + public override void _Ready() { Main = this; _camPos = GlobalPosition; } - //public override void _PhysicsProcess(float delta) + //public override void _PhysicsProcess(float delta); public override void _Process(float delta) { @@ -41,19 +41,14 @@ var player = RoomManager.Current.Player; var viewportContainer = RoomManager.Current.ViewportContainer; //var mousePos = InputManager.GetMousePosition(); - // 使用lerp,相机的位置移动到鼠标的位置 var camPos = player.GlobalPosition; //var camPos = player.GlobalPosition.LinearInterpolate(mousePos, 0); - // 用另一种方式使运动平稳 - _camPos = _camPos.LinearInterpolate(camPos, 5 * delta) + _shakeOffset; - // 计算新相机的“亚像素”位置 + //_camPos = camPos + _shakeOffset; + _camPos = _camPos.LinearInterpolate(camPos, Mathf.Min(5 * delta, 1)) + _shakeOffset; var camSubpixelPos = _camPos.Round() - _camPos; - // 更新主要视图端口的shader参数 (viewportContainer.Material as ShaderMaterial)?.SetShaderParam("offset", camSubpixelPos); - // 把相机调到新位置,然后旋转。 GlobalPosition = _camPos.Round(); } - /// /// 设置帧抖动, 结束后自动清零, 需要每一帧调用 diff --git a/DungeonShooting_Godot/src/game/role/Player.cs b/DungeonShooting_Godot/src/game/role/Player.cs index 112277c..8dd1e1f 100644 --- a/DungeonShooting_Godot/src/game/role/Player.cs +++ b/DungeonShooting_Godot/src/game/role/Player.cs @@ -45,23 +45,21 @@ } } private int _maxShield = 0; - + + private Vector2 _v1; + private Vector2 _v2; [Export] public PackedScene GunPrefab; public Player(): base("res://prefab/role/Player.tscn") { } - - public override void _EnterTree() - { - base._EnterTree(); - RoomManager.Current.Player = this; - } public override void _Ready() { base._Ready(); + + _v1 = _v2 = Position; //让相机跟随玩家 // var remoteTransform = new RemoteTransform2D(); @@ -97,6 +95,10 @@ { Face = FaceDirection.Left; } + + var f = Mathf.Clamp(Engine.GetPhysicsInterpolationFraction(), 0, 1); + Position = _v1.LinearInterpolate(_v2, f).Round(); + // GD.Print($"Position: {_realPos}, f: {f}"); if (Input.IsActionJustPressed("exchange")) //切换武器 { @@ -143,6 +145,7 @@ Move(delta); //播放动画 PlayAnim(); + //AnimatedSprite.Playing = false; } protected override void OnChangeHp(int hp) @@ -222,8 +225,11 @@ if (Mathf.IsZeroApprox(dir.y)) Velocity.y = Mathf.MoveToward(Velocity.y, 0, Friction * delta); else Velocity.y = Mathf.MoveToward(Velocity.y, dir.y * MoveSpeed, Acceleration * delta); - + + _v1 = Position = _v2; Velocity = MoveAndSlide(Velocity); + _v2 = Position; + Position = _v1.Round(); } // 播放动画 diff --git a/DungeonShooting_Godot/src/game/role/Role.cs b/DungeonShooting_Godot/src/game/role/Role.cs index cfe9a53..8320680 100644 --- a/DungeonShooting_Godot/src/game/role/Role.cs +++ b/DungeonShooting_Godot/src/game/role/Role.cs @@ -14,7 +14,7 @@ /// /// 移动速度 /// - public float MoveSpeed = 150f; + public float MoveSpeed = 120f; /// /// 所属阵营 diff --git a/DungeonShooting_Godot/src/game/room/RoomManager.cs b/DungeonShooting_Godot/src/game/room/RoomManager.cs index 138d9d0..64fef5a 100644 --- a/DungeonShooting_Godot/src/game/room/RoomManager.cs +++ b/DungeonShooting_Godot/src/game/room/RoomManager.cs @@ -15,7 +15,7 @@ public CanvasLayer UI; public Cursor Cursor { get; private set; } - public Player Player { get; set; } + public Player Player { get; private set; } public Node2D ObjectRoot { get; private set; } public YSort SortRoot { get; private set; } public Viewport Viewport { get; private set; } @@ -47,11 +47,11 @@ VisualServer.SetDefaultClearColor(color); //创建玩家 - var player = new Player(); - player.Position = new Vector2(100, 100); - player.Name = "Player"; + Player = new Player(); + Player.Position = new Vector2(100, 100); + Player.Name = "Player"; //SortRoot.AddChild(player); - player.PutDown(); + Player.PutDown(); } public override void _Ready()