func _physics_process(delta: float) → void:
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
# Handle jump.
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var direction := Input.get_axis("left", "right")
if direction:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
if direction > 0:
animated_sprite,flip_h = false
elif direction < 0:
animated_sprite.flip_h = true
# Apply Movement
if direction:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
Line 6:Unknown character “→”.Line 6:Expected “:” after function declaration.Line 6:Expected statement, found “void” instead.Line 8:Unexpected “if” in class body.Line 9:Unexpected “Identifier” in class body
const SPEED = 300.0
const JUMP_VELOCITY = -400.0
func _physics_process(delta: float) → void:
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
# Handle jump.
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var direction := Input.get_axis("left", "right")
if direction:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
if direction > 0:
animated_sprite,flip_h = false
elif direction < 0:
animated_sprite.flip_h = true
# Apply Movement
if direction:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
move_and_slide()```
Paste the code here again, but use preformatted text functionality please wrapping your code with ```
And please list all errors, we can’t help you if we don’t know what you’re dealing with.
The errors Line 4:Unknown character “→”.Line 4:Expected “:” after function declaration.Line 4:Expected statement, found “void” instead.Line 6:Unexpected “if” in class body.Line 7:Unexpected “Identifier” in class body.Line 10:Unexpected “Indent” in class body.Line 11:Unexpected “Identifier” in class body.Line 15:Expected end of file.
const JUMP_VELOCITY = -400.0
func _physics_process(delta: float) → void:
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
# Handle jump.
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY
# Get the input direction and handle the movement/deceleration.
# As good pactice, you should replace UI actions with custom gameplay actions.
var direction := Input.get_axis("left", "right")
if direction:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
if direction > 0:
animated_sprite,flip_h = false
elif direction < 0:
animated_sprite.flip_h = true
# Apply Movement
if direction:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
move_and_slide()```
You haven’t indented almost any of your code.
Please study this article about how GDscript code is supposed to look like, then correct yours with proper indentation.
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
# Handle jump.
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY
# Get the input direction and handle the movement/deceleration.
# As good pactice, you should replace UI actions with custom gameplay actions.
var direction := Input.get_axis("left", "right")
if direction:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
if direction > 0:
animated_sprite,flip_h = false
elif direction < 0:
animated_sprite.flip_h = true
# Apply Movement
if direction:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
move_and_slide()```
Line 4:Unknown character “→”.Line 4:Expected “:” after function declaration.Line 4:Expected statement, found “void” instead.Line 6:Unexpected “Indent” in class body.Line 7:Unexpected “Identifier” in class body.Line 10:Unexpected “if” in class body.Line 11:Unexpected “Identifier” in class body.Line 16:Unexpected “Indent” in class body.Line 17:Unexpected “Indent” in class body.Line 18:Expected end of file.
You’re still not indenting it correctly and now you don’t even have any function declaration. See below how it should look like, at least I think from the scraps of information I have, and assuming the code itself is correct.
const SPEED = 300.0
const JUMP_VELOCITY = -400.0
func _physics_process(delta: float) -> void:
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
# Handle jump.
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY
# Get the input direction and handle the movement/deceleration.
# As good pactice, you should replace UI actions with custom gameplay actions.
var direction := Input.get_axis("left", "right")
if direction:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
if direction > 0:
animated_sprite,flip_h = false
elif direction < 0:
animated_sprite.flip_h = true
# Apply Movement
if direction:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
move_and_slide()
Line 7:Mixed use of tabs and spaces for indentation.Line 11:Mixed use of tabs and spaces for indentation.Line 30:Unindent doesn’t match the previous indentation level.Line 30:Mixed use of tabs and spaces for indentation.Line 32:Expected end of file.
As the error says - you can’t mix spaces and tabs for indentation, so change all spaces in the indentations for tabs. I’m on mobile so I can’t see which are spaces and which tabs, but in the Godot Editor you should see the difference.