feat: fix the block pushing; add new groups for walls and pushable objects;

This commit is contained in:
2026-09-18 10:39:03 +02:00
parent 8ba607d1b0
commit 2b4b54612f
5 changed files with 13 additions and 5 deletions
+2 -1
View File
@@ -9,8 +9,9 @@ size = Vector2(16, 16)
atlas = ExtResource("1_83tkd")
region = Rect2(127.859436, 47.936436, 16.21347, 16.062302)
[node name="Block" type="RigidBody2D" unique_id=2096944035]
[node name="Block" type="RigidBody2D" unique_id=2096944035 groups=["pushable"]]
gravity_scale = 0.0
linear_damp = 10.0
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=195703280]
shape = SubResource("RectangleShape2D_bqpwv")
File diff suppressed because one or more lines are too long
+2
View File
@@ -795,6 +795,7 @@ tile_map_data = PackedByteArray("AAAIAP7/AAAAAAIAAAAKAP3/AAAAAAIAAAAMAP7/AAAAAAI
tile_set = SubResource("TileSet_ilnae")
[node name="Player" parent="ObstacleLayer" unique_id=1991398375 instance=ExtResource("1_2p8i2")]
push_strength = 100
[node name="Camera2D" type="Camera2D" parent="ObstacleLayer/Player" unique_id=1335060572]
zoom = Vector2(5, 5)
@@ -804,3 +805,4 @@ position = Vector2(136, -108)
[node name="Block" parent="." unique_id=2096944035 instance=ExtResource("6_12ovb")]
position = Vector2(0, -33)
lock_rotation = true
+3 -3
View File
@@ -3,6 +3,7 @@ class_name Player
@export var move_speed: float = 100
@export var hp: int = 10
@export var push_strength: int = 50
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
@@ -33,10 +34,9 @@ func _process(delta: float) -> void:
var collision: KinematicCollision2D = get_last_slide_collision()
if collision:
var collisision_node = collision.get_collider()
if collisision_node is RigidBody2D:
if collisision_node.is_in_group("pushable"):
var collision_normal: Vector2 = collision.get_normal()
collisision_node.apply_central_force(-collision_normal)
collisision_node.apply_central_force(-collision_normal * push_strength)
move_and_slide()
+5
View File
@@ -23,6 +23,11 @@ SceneManager="*uid://6txu74mchftj"
window/stretch/mode="canvas_items"
[global_group]
wall="A wall tilemap layer"
pushable="A pushuable object"
[physics]
3d/physics_engine="Jolt Physics"