#Changing scale didn't work like i exactly expected...
1 messages · Page 1 of 1 (latest)
func _physics_process(delta: float) -> void:
if Input.is_action_pressed("ui_right"):
velocity.x = SPEED * 1
character_body_2d.scale.x = -1
elif Input.is_action_pressed("ui_left"):
velocity.x = SPEED * -1
character_body_2d.scale.x = 1
i thought it would work but everytime it goes to the right it just keeps changing sides, but when i print the scale.x property, everything seems fine
even tried to fix it with the help of a friend
but neither of us could figure it out
Changing the X value on scale can lead to unexpected behaviours and advised to not do on Bodys.
as godot dev stated : "Godot does not allow scaling collision bodies or shapes in a non-uniform manner. Setting the X scale to -1 is performing non-uniform scaling (and negative scaling at that)."
Flip the visuals with flip_h, you dont have to do animations for both sides. you just have the one direction and flipping the sprite the animation will still work just fine.
yeah well i tried that and it works fine but the thing is the player animations change the rotation, so if i flip the visual then it ends up looking weird
this is how it looks, it just looks inconsistent, that's why i tried the scaling thing
Are you rotating the sprite itself? i didnt think flip_h would effect rotation. but you can probably pass in the direction as 1 or -1 and do the calculation for rotation based off that and just let flip_h deali with flipping the sprite.
Scaling the whole body X is def not recommended and leads to behaviour like you saw so. best to find another approach probably.
solved it, instead of doing whatever i was doing i changed the animation key values for the sprite when it looks to the other side