Godot Version
godot-4
Can anyone help!
Im working on a 2D point and click game, in early stages and i want to get my character to move but when i go to test it, im getting an error message. Its because line 7 has a ‘Unexpected “Identifier” in class body’.
I have no idea how to fix this as i cant see the problem. Code below
extends CharacterBody2D
var destination = Vector2()
var distance = Vector2()
var velocity = Vector2()
var snapPosition = Vector2()
Declare an export variable (can be set in the editor)
export var speed = 250
var margin = 1
Called when the node enters the scene tree for the first time.
func _ready():
destination = position
Called every frame. ‘delta’ is the elapsed time since the previous frame.
func _process(delta):
if position != destination:
distance = Vector2(destination - position)
velocity.x = distance.normalized().x * speed
velocity.y = distance.normalized().x * 0
move_and_slide(velocity)
if (distance.x * distance.x < margin):
set_position(snapPosition)
else:
move_and_slide(velocity * 0)
if(destination.x > position.x):
get_node( "Player_Sprite" ).set.flip_h( false )
if (destination.x < position.x):
get_node( "Player_Sprite" ).set.flip_h( true )
pass
func _input(event):
if Input.is_action_pressed (“ui_leftMouseClick”):
destination = get_global_mouse_position()
snapPosition.x = destination.x
snapPosition.y = destination.y