#Changing scale didn't work like i exactly expected...

1 messages · Page 1 of 1 (latest)

neon mantle
#

So, to make the player turn around, instead of doing flip_h = true to the sprite, i tried changing the scale.x of the characterbody2d to -1, that way i don't have to do all the animations of the animation_player to the other side. The thing is... this happened instead.

#

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

balmy quail
#

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.

neon mantle
balmy quail
#

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.

neon mantle
#

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