0 votes

it says "Attempt to call function 'rotate_x' in base 'null instance' on a null instance. Heres the code:

extends KinematicBody

var speed = 7
var accelaration = 20
var gravity = 9.8
var jump = 5

var mouse_sensitivity = 0.05

var direction = Vector3()
var velocity = Vector3()
var fall = Vector3()

onready var head = $Head

func ready():

func input(event):
if event is InputEventMouseMotion:
y(deg2rad(-event.relative.x * mousesensitivity))
x(deg2rad(-event.relative.y * mouse_sensitivity))

Godot version 4.0
in Engine by (16 points)

1 Answer

0 votes

Your code is hard to read because it's misformatted in the forums. However, the error is telling you that the object that you're calling rotate_x() on (your head reference) is not pointing to a valid object.

I see you got that reference with this code:

onready var head = $Head

That syntax is correct, but for it to work, your Head object must be a direct child of the node containing the posted script. If it is not, that reference will fail and you'll end up with the error you reported.

Without seeing your scene tree, it's hard to say much more other than your Head reference is currently null.

by (16,666 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.