Help
Asked Answered
A

9

0

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 answered 11/3 at 18:48 Comment(0)
J
0

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.

Jug answered 15/3 at 1:28 Comment(0)
D
0

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?

Drumfish answered 12/3 at 1:30 Comment(0)
A
0
Abutment answered 12/3 at 18:28 Comment(0)
D
0

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.

Drumfish answered 13/3 at 1:49 Comment(0)
A
0

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.

Abutment answered 14/3 at 19:2 Comment(0)
A
0

Abutment answered 14/3 at 19:8 Comment(0)
D
0

Your ready function is empty.
Delete it or type pass.

Drumfish answered 14/3 at 19:19 Comment(0)
J
0

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.

Jug answered 15/3 at 1:28 Comment(0)
A
0

Is there a way I can learn indentations?

Abutment answered 15/3 at 14:29 Comment(0)
J
0

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

Jug answered 15/3 at 15:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.