0 votes

please help me with this error from the tutorial "Improved First Person Character Controller (Godot FPS Tutorial)" by Garbaj.

Full Script:
extends KinematicBody

var speed = 10
var hacceleration = 6
var air
acceleration = 1
var normalacceleration = 6
var gravity = 20
var jump = 10
var full
contact = false

var mouse_sensitivity = 0.03

var direction = Vector3()
var hvelocity = Vector3()
var movement = Vector3()
var gravity
vec = Vector3()

onready var head = $Head
onready var ground_check = $GroundCheck

func _ready():
pass

func input(event):
if event is InputEventMouseMotion:
rotate
y(deg2rad(-event.relative.x * mousesensitivity))
head.rotate
x(deg2rad(-event.relative.y * mouse_sensitivity))
head.rotation.x = clamp(head.rotation.x, deg2rad(-89), deg2rad(89))

func physicsprocess(delta):

direction = Vector3()

full_contact = ground_check.is_colliding()        #ERROR IS HERE

if not is_on_floor():
    gravity_vec += Vector3.DOWN * gravity * delta
    h_acceleration = air_acceleration
elif is_on_floor() and full_contact:
    gravity_vec = -get_floor_normal() * gravity
    h_acceleration = normal_acceleration
else:
    gravity_vec = -get_floor_normal()
    h_acceleration = normal_acceleration

if Input.is_action_just_pressed("jump") and (is_on_floor() or ground_check.is_colliding()):
    gravity_vec = Vector3.UP * jump

if Input.is_action_pressed("move_forward"):
    direction -= transform.basis.z
elif Input.is_action_pressed("move_backward"):
    direction += transform.basis.z
if Input.is_action_pressed("move_left"):
    direction -= transform.basis.x
elif Input.is_action_pressed("move_right"):
    direction += transform.basis.x

direction = direction.normalized()
h_velocity = h_velocity.linear_interpolate(direction * speed, h_acceleration * delta)
movement.z = h_velocity.z + gravity_vec.z
movement.x = h_velocity.x + gravity_vec.x
movement.y = gravity_vec.y

move_and_slide(movement, Vector3.UP)
in Engine by (22 points)

1 Answer

0 votes
Best answer

The code related to the is_colliding() checks looks OK. The error is indicating that your ground_check variable is null. In the code, that's set here:

onready var ground_check = $GroundCheck

So, that assumes there is a node named GroundCheck that is a child of the node that contains the script itself. I'd assume that node doesn't exist. Likely, it's just named wrong in the scene tree (or just has a typo in the name).

by (10,690 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 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.

Categories