How to fix unexpected indentation?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Miguelxi

I got this error when I typed in “get_input()”. Does anybody know how to fix this?
This is the code:
Extends kinematic body
var gravity =Vector3.DOWN * 12
var speed = 4
var jump_speed = 6
var velocity = Vector3()
func _physics_process(delta):
velocity += gravity * delta
get_input()
velocity =move_and_slide(velocity,Vector3.UP)
func get_input()

:bust_in_silhouette: Reply From: kidscancode

Nobody can help you if you don’t actually show the code that has the error.

That said, the error message is clear: you have indentation and GDScript does not expect indentation there.

Sorry here’s the code:
Extends kinematic body
var gravity =Vector3.DOWN * 12
var speed = 4
var jump_speed = 6
var velocity = Vector3()
func _physics_process(delta):
velocity += gravity * delta
get_input()
velocity =move_and_slide(velocity,Vector3.UP)
func get_input()

Miguelxi | 2021-03-10 00:19

Now you’ve pasted it so that the formatting is lost. It’s impossible to tell from that what you had indented and what you didn’t.

That code should look something like this:

extends KinematicBody

var gravity =Vector3.DOWN * 12
var speed = 4
var jump_speed = 6
var velocity = Vector3()

func _physics_process(delta):
    velocity += gravity * delta
    get_input()
    velocity =move_and_slide(velocity, Vector3.UP)

func get_input():
    # There needs to be code here for the get_input() function.

When typing or pasting code here, use the “Code Sample” button in the bar, it looks like “{}”.

kidscancode | 2021-03-10 00:31

Extends kinematic body

var gravity =Vector3.DOWN * 12
var speed = 4
var jumpspeed = 6
var velocity = Vector3()
func _physicsprocess(delta):
velocity += gravity * delta
getinput()
velocity =moveandslide(velocity,Vector3.UP)
func getinput()

Miguelxi | 2021-03-10 00:38

That’s still not correct. Indentation matters in GDScript - see my example code. Also, I can’t see how you don’t have an error on the first line since “KinematicBody” is the correct name of the Godot class.

kidscancode | 2021-03-10 00:55