Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | jamecz |
Im using Godot 3.0.
In a new project, I’ve copied and pasted a script from another project I did, just a platformer tutorial. However, the script gives me a warning: “Attempt to call function ‘play’ in base ‘null instance’ on a null instance.” Heres the code Im using
extends KinematicBody2D
const GRAVITY = 5
const SPEED = 37
const JUMPHEIGHT = -250
const UP = Vector2(0,-1)
var motion = Vector2()
func _physics_process(delta):
motion.y += GRAVITY
if Input.is_action_pressed("ui_right"):
motion.x = SPEED
$AnimationPlayer.flip_h = false
$AnimationPlayer.play("run")
elif Input.is_action_pressed("ui_left"):
motion.x = -SPEED
$AnimationPlayer.flip_h = true
$AnimationPlayer.play("run")
else:
motion.x = 0
$AnimationPlayer.play("idle")
if is_on_floor():
if Input.is_action_pressed("ui_up"):
motion.y = JUMPHEIGHT
else:
if motion.y < 0:
$AnimationPlayer.play("jump")
if motion.y > 0:
$AnimationPlayer.play("fall")
motion = move_and_slide(motion, UP)
pass