- Edited
Hello everyone. I know this is a popular topic but I'm pretty new to Godot and programming in general, so bear with me please.
My wife and I decided to make a game and from watching tutorials on youtube we've learned we can flip our AnimatedSprite using flip_h.
But the thing is that this won't flip the collision shape and although I've read about scale.x -1, and tried to look at my code and figure out where to put it, I have no idea where (or how) to implement that to my code.
I'm pasting my code below and adding a screenshot of my layers order, if there is anyone patient enough to help me I will be extremely grateful.
extends KinematicBody2D
const SPEED = 100
const GRAVITY = 10
const JUMPFORCE = -288
const FLOOR = Vector2(0, -1)
var velocity = Vector2()
var on_ground = false
func _physics_process(delta):
if Input.is_action_pressed("p_right"):
velocity.x = SPEED
$AnimatedSprite.play("walk")
$AnimatedSprite.flip_h = false
elif Input.is_action_pressed("p_left"):
velocity.x = -SPEED
$AnimatedSprite.play("walk")
$AnimatedSprite.flip_h = true
else:
velocity.x = 0
if on_ground == true:
$AnimatedSprite.play("idle")
if Input.is_action_just_pressed("p_jump"):
if on_ground == true:
velocity.y = JUMPFORCE
on_ground = false
velocity.y += GRAVITY
if is_on_floor():
on_ground = true
else:
on_ground = false
if velocity.y < -1:
$AnimatedSprite.play("jump")
else:
$AnimatedSprite.play("fall")
velocity = move_and_slide(velocity, FLOOR)
velocity.x = lerp(velocity.x,0,0.2)
If you are curious why my character has 3 collision shapes: My character, a Llama, has 3 collision shapes. I tried to add one CollisionPolygon2D but that didn't work as I wanted
Thank you!