Invalid operations nil and float in operator *

Godot Version

Version 4.2

Question

I’m EXTREMELY new to this. Trying to teach myself to make games. I was following a tutorial a,s typed everything exactly how he did. But, I get this error.

“invalid operations nil and float in operator *”

I have no errors other than when I try to launch. But when I do, it puts a yellow arrow on line 12. I have no idea what to do. Please help.

Here’s my full code:

extends CharacterBody3D

const SPEED = 5.0
const JUMP_VELOCITY = 4.5

var gravity = ProjectSettings.get_setting(“physics/3d/default-gravity”)

func _physics_process(delta):
if not is_on_floor():
velocity.y -= gravity * delta

if Input.is_action_just_pressed("ui_accept") and is_on_floor():
	velocity.y = JUMP_VELOCITY


var input_dir = Input.get_vector("ui_left","ui_right", "ui_up","ui_down")
var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
if direction:
	velocity.x = direction.x * SPEED
	velocity.z = direction.z * SPEED

move_and_slide()

The error means that you are trying to multiply a null value with a float value.

You have a typo in that line, it should be var gravity = ProjectSettings.get_setting(“physics/3d/default_gravity”)

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.