I’m making my first tutorial project to learn the basics of making games with Godot with a Pin Pon game. My project is going decently but when making the ball’s code which is attached to its CharacterBody2D it gives me this error: “Error at (3, 16): Unexpected identifier” in class body. The code is the following:
extends CharacterBody2D
func _physics_process(delta: float) → void:
move_and_collide(velocity * speed * delta)
-------------------------------------------------------------------- (spacer, not in my code) ---------------------------
Also, I don’t know if this matters but I have a ColorRect for the shape and color of the ball and a CollisionShape2D for the physics, both as the child of the CharacterBody2D.
Because you’re trying to manipulate the property velocity outside a function, you even need to call it because velocity already starts as zero, but if for some reason you want to change it at the start you need to do it insde a function (like in the _ready function)
Ah yes, but then you can’t have this piece of code floating around outside of the function, it needs to be moved inside the function. velocity = Vector2.ZERO
Thank you so much! Yes, it was exactly that, I moved the velocity property inside the start function, and it worked as expected. Once again, thank you so much!