0 votes

Hi,
I have a game with a player that have a code that I copied and edited from here, and I have a downloaded project from a video that do the same, and when I run and move my cursor, appears the following error message: Attempt to call function 'rotate_x' in base 'null instance' on a null instance.
The code that I used is this:

extends KinematicBody

const GRAVITY = -24.8
var vel = Vector3()
const MAXSPEED = 20
const JUMP
SPEED = 18
const ACCEL = 4.5

var dir = Vector3()

const DEACCEL= 16
const MAXSLOPEANGLE = 40

var camera
var rotation_helper

var MOUSE_SENSITIVITY = 0.05

func ready():
camera = $RotationHelper/PlayerEyes
rotation
helper = $Rotation_Helper

Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)

func physicsprocess(delta):
processinput(delta)
process
movement(delta)

func process_input(delta):

# ----------------------------------
# Walking
dir = Vector3()
var cam_xform = camera.get_global_transform()

var input_movement_vector = Vector2()

if Input.is_action_pressed("movement_forward"):
    input_movement_vector.y += 1
if Input.is_action_pressed("movement_backward"):
    input_movement_vector.y -= 1
if Input.is_action_pressed("movement_left"):
    input_movement_vector.x -= 1
if Input.is_action_pressed("movement_right"):
    input_movement_vector.x += 1

input_movement_vector = input_movement_vector.normalized()

# Basis vectors are already normalized.
dir += -cam_xform.basis.z * input_movement_vector.y
dir += cam_xform.basis.x * input_movement_vector.x
# ----------------------------------

# ----------------------------------
# Jumping
if is_on_floor():
    if Input.is_action_just_pressed("movement_jump"):
        vel.y = JUMP_SPEED
# ----------------------------------

# ----------------------------------
# Capturing/Freeing the cursor
if Input.is_action_just_pressed("ui_cancel"):
    if Input.get_mouse_mode() == Input.MOUSE_MODE_VISIBLE:
        Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
    else:
        Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
# ----------------------------------

func process_movement(delta):
dir.y = 0
dir = dir.normalized()

vel.y += delta * GRAVITY

var hvel = vel
hvel.y = 0

var target = dir
target *= MAX_SPEED

var accel
if dir.dot(hvel) > 0:
    accel = ACCEL
else:
    accel = DEACCEL

hvel = hvel.linear_interpolate(target, accel * delta)
vel.x = hvel.x
vel.z = hvel.z
vel = move_and_slide(vel, Vector3(0, 1, 0), 0.05, 4, deg2rad(MAX_SLOPE_ANGLE))

func input(event):
if event is InputEventMouseMotion and Input.get
mousemode() == Input.MOUSEMODECAPTURED:
rotation
helper.rotatex(deg2rad(event.relative.y * MOUSESENSITIVITY * -1))
self.rotatey(deg2rad(event.relative.x * MOUSESENSITIVITY * -1))

    var camera_rot = rotation_helper.rotation_degrees
    camera_rot.x = clamp(camera_rot.x, -70, 70)
    rotation_helper.rotation_degrees = camera_rot

I don't know what is happening.

Thanks in advanced.

in Engine by (353 points)

1 Answer

+1 vote
Best answer

Attempt to call function 'whatever' in base 'null instance' on a null instance.

is one of the most common Godot error, it means you are trying to call the function whatever from a node that does not exist.
In your case you are trying to call rotate_x, whic is located in the func _input(event): part.
much likely, rotation_helper is a variable that does not contain anything

by (1,457 points)
selected by
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 webmaster@godotengine.org with your username.