resized player and player collision

This commit is contained in:
2022-12-10 21:35:20 +01:00
parent 57cbbacc47
commit 114c8045eb
3 changed files with 13 additions and 9 deletions

View File

@@ -12,18 +12,21 @@ animations = [{
}] }]
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_38v5o"] [sub_resource type="CapsuleShape2D" id="CapsuleShape2D_38v5o"]
radius = 43.0 radius = 18.057
height = 132.0 height = 56.0051
[node name="player" type="CharacterBody2D"] [node name="player" type="CharacterBody2D"]
process_mode = 1 process_mode = 1
script = ExtResource("1_qehox") script = ExtResource("1_qehox")
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."] [node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
position = Vector2(-0.0625, -17.0625)
scale = Vector2(0.733398, 0.733398)
frames = SubResource("SpriteFrames_2x1cy") frames = SubResource("SpriteFrames_2x1cy")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."] [node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2(0, 1) position = Vector2(0, 12)
rotation = 1.57345
shape = SubResource("CapsuleShape2D_38v5o") shape = SubResource("CapsuleShape2D_38v5o")
[node name="Camera2D" type="Camera2D" parent="."] [node name="Camera2D" type="Camera2D" parent="."]
@@ -31,6 +34,6 @@ current = true
zoom = Vector2(0.8, 0.8) zoom = Vector2(0.8, 0.8)
[node name="ray_cast_2d" type="RayCast2D" parent="."] [node name="ray_cast_2d" type="RayCast2D" parent="."]
target_position = Vector2(0, 100) target_position = Vector2(0, 64)
collision_mask = 2 collision_mask = 2
collide_with_areas = true collide_with_areas = true

View File

@@ -15,4 +15,4 @@ tile_set = ExtResource("2_kvjhj")
cell_quadrant_size = 64 cell_quadrant_size = 64
format = 2 format = 2
layer_0/z_index = 1 layer_0/z_index = 1
layer_0/tile_data = PackedInt32Array(65535, 0, 0, 0, 0, 0, 1, 0, 0, 65534, 0, 0, 65533, 0, 0, -3, 0, 0, -2, 0, 0, -1, 0, 0, -65536, 0, 0, -65535, 0, 0, 65529, 1, 65536, 65541, 1, 65536, -196605, 1, 65536, 196603, 1, 65536) layer_0/tile_data = PackedInt32Array(1, 0, 0, 65533, 0, 0, -3, 0, 0, -65535, 0, 0, 65529, 1, 65536, 65541, 1, 65536, -196605, 1, 65536, 196603, 1, 65536, -196603, 1, 65536, -196600, 1, 65536)

View File

@@ -24,10 +24,11 @@ public partial class player : CharacterBody2D
public override void _Process(double delta) public override void _Process(double delta)
{ {
//set ray_cast target position //set ray_cast target position
if (Input.IsActionJustPressed("move_right")) GetNode<RayCast2D>("ray_cast_2d").TargetPosition = new Vector2(100, 0); int raylength = 64;
if (Input.IsActionJustPressed("move_left")) GetNode<RayCast2D>("ray_cast_2d").TargetPosition = new Vector2(-100, 0); if (Input.IsActionJustPressed("move_right")) GetNode<RayCast2D>("ray_cast_2d").TargetPosition = new Vector2(raylength, 0);
if (Input.IsActionJustPressed("move_down")) GetNode<RayCast2D>("ray_cast_2d").TargetPosition = new Vector2(0, 100); if (Input.IsActionJustPressed("move_left")) GetNode<RayCast2D>("ray_cast_2d").TargetPosition = new Vector2(-raylength, 0);
if (Input.IsActionJustPressed("move_up")) GetNode<RayCast2D>("ray_cast_2d").TargetPosition = new Vector2(0, -100); if (Input.IsActionJustPressed("move_down")) GetNode<RayCast2D>("ray_cast_2d").TargetPosition = new Vector2(0, raylength);
if (Input.IsActionJustPressed("move_up")) GetNode<RayCast2D>("ray_cast_2d").TargetPosition = new Vector2(0, -raylength);
//call event in raycasted object //call event in raycasted object
if (Input.IsActionJustPressed("ui_accept") && GetNode<RayCast2D>("ray_cast_2d").IsColliding()) if (Input.IsActionJustPressed("ui_accept") && GetNode<RayCast2D>("ray_cast_2d").IsColliding())