added interaction_area to player for interacting with overlapping objects
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
[gd_scene load_steps=5 format=3 uid="uid://ujfhvssvbgpg"]
|
[gd_scene load_steps=6 format=3 uid="uid://ujfhvssvbgpg"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://src/scene-scripts/player.cs" id="1_qehox"]
|
[ext_resource type="Script" path="res://src/scene-scripts/player.cs" id="1_qehox"]
|
||||||
[ext_resource type="Texture2D" uid="uid://ciidukjv5k6oa" path="res://assets/textures/debug/banana.png" id="2_1l1co"]
|
[ext_resource type="Texture2D" uid="uid://ciidukjv5k6oa" path="res://assets/textures/debug/banana.png" id="2_1l1co"]
|
||||||
@@ -15,6 +15,8 @@ animations = [{
|
|||||||
radius = 21.0
|
radius = 21.0
|
||||||
height = 66.0
|
height = 66.0
|
||||||
|
|
||||||
|
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_jpkwv"]
|
||||||
|
|
||||||
[node name="player" type="CharacterBody2D"]
|
[node name="player" type="CharacterBody2D"]
|
||||||
script = ExtResource("1_qehox")
|
script = ExtResource("1_qehox")
|
||||||
|
|
||||||
@@ -27,3 +29,11 @@ shape = SubResource("CapsuleShape2D_38v5o")
|
|||||||
[node name="Camera2D" type="Camera2D" parent="."]
|
[node name="Camera2D" type="Camera2D" parent="."]
|
||||||
current = true
|
current = true
|
||||||
zoom = Vector2(0.8, 0.8)
|
zoom = Vector2(0.8, 0.8)
|
||||||
|
|
||||||
|
[node name="interaction_area" type="Area2D" parent="."]
|
||||||
|
|
||||||
|
[node name="interaction_collision" type="CollisionShape2D" parent="interaction_area"]
|
||||||
|
position = Vector2(-2.27374e-13, 65)
|
||||||
|
rotation = 1.5708
|
||||||
|
scale = Vector2(3, 5)
|
||||||
|
shape = SubResource("CapsuleShape2D_jpkwv")
|
||||||
|
@@ -4,14 +4,11 @@ public partial class player : CharacterBody2D
|
|||||||
{
|
{
|
||||||
[Export]
|
[Export]
|
||||||
public int speed = 400;
|
public int speed = 400;
|
||||||
// Called when the node enters the scene tree for the first time.
|
|
||||||
public override void _Ready()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
public override void _Ready()
|
||||||
|
{
|
||||||
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
}
|
||||||
public override void _PhysicsProcess(double delta)
|
public override void _PhysicsProcess(double delta)
|
||||||
{
|
{
|
||||||
MoveAndCollide(new Vector2
|
MoveAndCollide(new Vector2
|
||||||
(
|
(
|
||||||
@@ -23,4 +20,12 @@ public partial class player : CharacterBody2D
|
|||||||
* speed * (float)delta
|
* speed * (float)delta
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
public override void _Process(double delta)
|
||||||
|
{
|
||||||
|
//rotates just interaction_area instead of whole player
|
||||||
|
if (Input.IsActionJustPressed("move_right")) GetNode<Area2D>("interaction_area").Rotation = Mathf.Pi / -2;
|
||||||
|
if (Input.IsActionJustPressed("move_left")) GetNode<Area2D>("interaction_area").Rotation = Mathf.Pi / 2;
|
||||||
|
if (Input.IsActionJustPressed("move_down")) GetNode<Area2D>("interaction_area").Rotation = 0;
|
||||||
|
if (Input.IsActionJustPressed("move_up")) GetNode<Area2D>("interaction_area").Rotation = Mathf.Pi;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user