Godot Version
v4.3.stable.official [77dcf97d8]
Question
I’m trying to create ladders for a 2D platformer game and I need the collision shape and amount of sprites to change to fit the size I want the ladder to be in.
The problem I’m facing is because I add an @export variable to the ladder called size, that would reshape the collision box and change the sprite frame. I do not understand why two separate nodes inherit the collision box from one another, like, if I change the box for one ladder (via the editor, with editable children, or through the variable I created) the other one also changes.
I am avoiding having multiple small nodes to make a large ladder (I tried it and it did not work, but if someone has any idea I would appreciate it aswell).
My code is as follows:
extends Area2D
@onready var collision_shape_2d = $CollisionShape2D
@onready var sprite_2d = $Sprite2D
@export var size:int = 1
func _physics_process(delta):
if size <= 0:
size = 1
sprite_2d.frame = size - 1
func _on_body_entered(body):
if body is Player:
body.enter_ladder = true
func _on_body_exited(body):
if body is Player:
body.enter_ladder = false
body.is_on_ladder = false
These pictures show what happens inside the editor, I really don’t get it:
If anyone knows if it is possible to “unlink” these two collision boxes in any way I would greatly appreciate it. Any other solution is still very welcome. Thank you all.