diff --git a/scenes/player.tscn b/scenes/player.tscn index 546b901..4188689 100644 --- a/scenes/player.tscn +++ b/scenes/player.tscn @@ -61,22 +61,36 @@ height = 43.9998 process_mode = 1 script = ExtResource("1_qehox") -[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."] +[node name="rotation_center" type="Marker2D" parent="."] + +[node name="ray_cast_2d" type="RayCast2D" parent="rotation_center"] +rotation = 3.14159 +target_position = Vector2(-64, 0) +collision_mask = 2 +collide_with_areas = true + +[node name="animated_sprite_2d" type="AnimatedSprite2D" parent="."] position = Vector2(-0.0625, -17.0625) scale = Vector2(0.733398, 0.733398) frames = SubResource("SpriteFrames_2x1cy") animation = &"move_down" -[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +[node name="collision_shape" type="CollisionShape2D" parent="."] position = Vector2(0, 12) rotation = 1.57345 shape = SubResource("CapsuleShape2D_38v5o") -[node name="Camera2D" type="Camera2D" parent="."] +[node name="camera_2d" type="Camera2D" parent="."] current = true zoom = Vector2(0.8, 0.8) +rotation_smoothing_enabled = true +drag_horizontal_enabled = true +drag_vertical_enabled = true +drag_left_margin = 0.15 +drag_top_margin = 0.15 +drag_right_margin = 0.15 +drag_bottom_margin = 0.15 +editor_draw_drag_margin = true -[node name="ray_cast_2d" type="RayCast2D" parent="."] -target_position = Vector2(0, 64) -collision_mask = 2 -collide_with_areas = true +[node name="audio_listener_2d" type="AudioListener2D" parent="."] +current = true diff --git a/src/scene-scripts/player.cs b/src/scene-scripts/player.cs index 1f59872..3ba14e7 100644 --- a/src/scene-scripts/player.cs +++ b/src/scene-scripts/player.cs @@ -5,14 +5,14 @@ public partial class player : CharacterBody2D { [Export] public string playerName; [Export] public int speed = 200; - public float rayCastLength; public Vector2 movement; public AnimatedSprite2D animatedSprite; + public Marker2D rotCenter; public override void _Ready() { - rayCastLength = GetNode("ray_cast_2d").TargetPosition.y; - animatedSprite = GetNode("AnimatedSprite2D"); + animatedSprite = GetNode("animated_sprite_2d"); + rotCenter = GetNode("rotation_center"); } public void ChangeProcess(bool process) { @@ -22,18 +22,17 @@ public partial class player : CharacterBody2D public override void _PhysicsProcess(double delta) { movement = Input.GetVector("move_left", "move_right", "move_up", "move_down"); + rotCenter.Rotation = movement.Angle(); MoveAndCollide(movement * speed * (float)delta); } public override void _Process(double delta) { - //set ray_cast target position - RayCast2D rayCast = GetNode("ray_cast_2d"); - Vector2 rayCastPosition = new Vector2((float)Math.Round(movement.x), (float)Math.Round(movement.y)) * rayCastLength; - if (rayCastPosition.Length() != 0) rayCast.TargetPosition = rayCastPosition; + //call event in raycasted object /*if (Input.IsActionJustPressed("ui_accept") && rayCast.IsColliding()) rayCast.GetCollider().Call("OnInteraction", playerName);*/ - //animation system (with controller support wcih cant get normalized vector) + + //animation system (with controller support wich cant get normalized vector) if (movement.Length() != 0) animatedSprite.Play(); else