![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Bidoofking756 |
So basically I am making a prototype for my game right now, and I am having a problem with Godot flip h. In the game, when I try and flip h, half of the image is out of the collisionshape2D. I am not sure how to fix this.
here is my code:
extends KinematicBody2D
const gravity = 20
const jump = -400
const acceleration = 5
const Floor = Vector2(0, -1)
const max_speed = 2
var velocity = Vector2()
var onground = true
func _physics_process(delta):
if Input.is_action_pressed("ui_right"):
velocity.x += acceleration
if velocity.x > min(velocity.x+acceleration, max_speed ):
$AnimatedSprite.flip_h = false
$AnimatedSprite.play("Run")
elif Input.is_action_pressed("ui_left"):
velocity.x -= acceleration
if velocity.x > min(velocity.x-acceleration, -max_speed):
$AnimatedSprite.flip_h = true
$AnimatedSprite.play("Run")
else:
velocity.x = 0
$AnimatedSprite.play("Idle")
if Input.is_action_pressed("ui_up"):
if onground == true:
$AnimatedSprite.play("Jump")
velocity.y = jump
onground = false
$AnimatedSprite.play("Idle")
if velocity.y < 0:
$AnimatedSprite.play("Jump")
if is_on_floor():
onground = true
else:
onground == false
if velocity.y< 0:
$AnimatedSprite.play("Jump")
else:
$AnimatedSprite.play("Fall")
velocity.y +=gravity
velocity = move_and_slide(velocity, Floor)