–1 vote

Well, I'm trying to make a camera that follows the character, and I'm guiding myself with chatgtp, so as not to ask everything, but I have a problem/error that not even botgtp can find.
The Error(8,20): Expected ',' or '.'
(the script is from chatgtp, in fact, I don't even know if it works for a camera that follows
the character).

(The line that appears in red is that of: func _process(delta: float): )

Here is the script:

class CameraFollower extends Sprite:
export var velocity = 10 

func _process(delta: float):
    var velocity = Vector2()
    if Input.is_action_pressed("move_right"):
        vel.x += velocity*delta
    var global_position = get_global_transform().origin
    var destination = get_viewport().get_camera().project_position(global_position)
    var direction = destination - global_position
    direction = direction.normalized()
    move_and_slide(direction * velocity * delta)
Godot version v3.0.6.stable.custom.build
in Engine by (11 points)

There's no guarantee that ChatGPT will not produce buggy code. In fact, answers to Stack Overflow created using CHatGPT have been banned for this reason.

1 Answer

+1 vote

Feels weird debugging AI code but anyway this line:

class CameraFollower extends Sprite:

should be two lines with no trailing colon:

extends Sprite
class_name CameraFollower

I wonder how the AI missed that.

by (2,017 points)

It looks like got GodotScript and C# mixxed up.

It continues with the blessed error, (the script is attached with the sprite, I took it from a tutorial on how to make the camera follow the character, but for some reason no errors appeared, but, as now, it changed a lot, I think not it will work.

extends Sprite

export var velocity = 10

func process(delta: float):
var velocity = Vector2()
if Input.is
actionpressed("moveright"):
velocity.x += velocity*delta
var global_position = get_global_transform().origin
var destination = get_viewport().get_camera().project_position(global_position)
var direction = destination - global_position
direction = direction.normalized()
move_and_slide(direction * velocity * delta)

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.