extends KinematicBody2D
const UP = Vector2(0, -1)
const GRAVITY = 20
const ACCELERATION = 50
const SPEED = 200
const JUMP_HEIGHT = -550
var motion = Vector2()
func physicsprocess(delta):
motion.y += GRAVITY
var friction = false
if Input.is_action_pressed("right"):
motion.x = min(motion.x+ACCELERATION, SPEED)
$AnimatedSprite.flip_h = false
$AnimatedSprite.play("walk")
elif Input.is_action_pressed("left"):
motion.x = max(motion.x-ACCELERATION, -SPEED)
$AnimatedSprite.flip_h = true
$AnimatedSprite.play("walk")
else:
$AnimatedSprite.play("idle")
friction = true
if is_on_floor():
if Input.is_action_pressed("up"):
motion.y = JUMP_HEIGHT
if friction == true:
motion.x = lerp(motion.x,0 ,0.2)
else:
if motion.y <0:
$AnimatedSprite.play("jump")
else:
$AnimatedSprite.play("fall")
if friction == true:
motion.x = lerp(motion.x,0 ,0.5)
motion = move_and_slide(motion, UP)
whats the prob of my code?
it says that attempt to call function on null instance
on line 24($AnimatedSprite.play("idle"))
PS: it works fine with i didnt insert the camera 2d
but when i insert the camera2d it just promt a message : attempt to call function on null instance
please help im new in this !