Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | MaybeAnonymous |
35 position.x = clamp(position.x, 0 + col_size.x/2, screen_size.x
- col_size.x/2)
36 position.y = clamp(position.y, 0 + col_size.y/2, screen_size.y
- col_size.y/2)
I have that code, and it works! But, how would I play an animation only if it’s not on the edge of the screen? ( col_size is the size of CollisionShape2D, screen_size is self explanatory )
19 if input_map != Vector2.ZERO:
20 c_vel = input_map * speed_m
21 animator.play("Walk")
22
23 # If moving horizontally
24 if input_map.x != 0:
25 $Sprite.flip_h = input_map.x < 0
26 else:
27 c_vel = Vector2.ZERO
28 animator.play("Idle")
( c_vel is the current speed, input_map is a Vector2 getting the input, speed_m is the multiplier )
I want to play “Idle” instead of “Walk” if the character is on the edge, would be nice to have a variable like that