0 votes

the hit box is offset from the character the animation is on the left when the hitbox is on the right
here is my code

extends KinematicBody2D

const UP = Vector2(0,-1)
const GRAVITY = 20
const MAXSPEED = 80
const MAXGRAVITY = 200
const JUMPSPEED = 300
const ACCEL = 10

var movement = Vector2()
var facing_right = true

func _ready():

pass # Replace with function body.

func physicsprocess(_delta):

movement.x = clamp(movement.x, -MAXSPEED,MAXSPEED)

if facing_right == true:
    $Sprite.scale.x = 1
else:
    $Sprite.scale.x = -1

if Input.is_action_pressed("left"):
    movement.x -= ACCEL
    facing_right = false
    $AnimationPlayer.play("Walk")
elif Input.is_action_pressed("right"):
    movement.x += ACCEL
    facing_right = true
    $AnimationPlayer.play("Walk")
else:
    movement.x = lerp(movement.x,0,0.2)
    $AnimationPlayer.play("idle")

if is_on_floor():
    if Input.is_action_just_pressed("jump"):
        movement.y = -JUMPSPEED

movement.y+= GRAVITY

if movement.y> MAXGRAVITY:
    movement.y=MAXGRAVITY

movement= move_and_slide(movement,UP)
in Engine by (12 points)

1 Answer

+1 vote

An image of your sprite would help. But I bet the issue is that your sprite isn't centered so when you flip it, the hitbox is off. Try changing the offset of your sprite and using the flip_h property to flip the sprite.

by (8,526 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.