Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Gedzi752 |
This is my 2nd day using godot and making games in general. I took some movement code from a video on yt and made a single sprite for my character (not animated, for now) and it moves okay but when i turn left the sprite changes its scale to -1 and so does the collision box (probably) but the collision box goes out of the character to the right so an arm goes through tiles. I tried to find an answer but i couldnt find anything thats why i created an account here to ask.
here is the script:
extends KinematicBody2D
const GRAVITY = 35
const JUMP_FORCE = 550
const SPEED = 300
const ACCEL = 0.4
const MAXACCEL = 800
onready var sprite = $Sprite
var velocity = Vector2.ZERO
func _unhandled_input(event):
if event.is_action_pressed("jump") && is_on_floor():
velocity.y = -JUMP_FORCE
func _physics_process(_delta):
velocity.y += GRAVITY
if velocity.y > MAXACCEL:
velocity.y = MAXACCEL
var dir = Input.get_action_strength("right") - Input.get_action_strength("left")
if dir != 0:
sprite.scale.x = dir
velocity.x = lerp(velocity.x, SPEED * dir, ACCEL)
velocity = move_and_slide(velocity, Vector2.UP)