added interaction_area to player for interacting with overlapping objects

This commit is contained in:
2022-11-30 18:42:21 +01:00
parent c01a20e603
commit 68d16fbd4f
2 changed files with 23 additions and 8 deletions

View File

@@ -4,14 +4,11 @@ public partial class player : CharacterBody2D
{
[Export]
public int speed = 400;
// Called when the node enters the scene tree for the first time.
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 _Ready()
{
}
public override void _PhysicsProcess(double delta)
{
MoveAndCollide(new Vector2
(
@@ -23,4 +20,12 @@ public partial class player : CharacterBody2D
* 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;
}
}