extends CharacterBody2D
var Player
func _physics_process(delta):
var direction =
global_position.direction_to(Player.global_position)
velocity = direction * 300.0
move_and_slide()
extends CharacterBody2D
var Player
func _physics_process(delta):
var direction =
global_position.direction_to(Player.global_position)
velocity = direction * 300.0
move_and_slide()
Abutment There's a indent error
Jesusemora has already explained the problem, but when posting code as text, place ~~~ on lines before and after the code. If you don't do that, the indentation is not visible here.
Please elaborate???
This appears to be an enemy AI script, at a glimpse I would say it should follow the player.
What is the problem?
Gdscript requires correct indentation like in python.
var direction = global_position
HAS to be all in the same line.
And direction = velocity
has to be at the same level as the line before, go to the beggining of the text and press backspace once to delete one tab.
extends CharacterBody2D
var Player
func _ready():
func _physics_process(delta):
var direction = global_position.direction_to(Player.global_position)
velocity = direction * 300.0
move_and_slide()
There's a indent error on line 9, and I've tried to find it on my own, but no luck.
Your ready function is empty.
Delete it or type pass
.
Abutment There's a indent error
Jesusemora has already explained the problem, but when posting code as text, place ~~~ on lines before and after the code. If you don't do that, the indentation is not visible here.
Is there a way I can learn indentations?
Have you done the Getting Started section of the documentation, including the first 2D game (Dodge the Creeps)? There are many examples there.
https://docs.godotengine.org/en/4.2/getting_started/introduction/index.html
© 2022 - 2024 — McMap. All rights reserved.