This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

Here is my code:

var curHP : int = 10
var maxHP : int = 10
var damage : int = 1

var gold : int = 0

var attackRate : float = 0.3
var lastAttackTime : int = 0

var moveSpeed : float = 5.0
var jumpForce : float = 10.0
var gravity : float = 15.0

var vel = Vector3()

onready var camera = get_node("CameraOrbit")
onready var attackCast = get_node("AttackRayCast")

func _physics_process (delta):
    vel.x = 0
    vel.z = 0

var input = Vector3()


if Input.is_action_pressed("move_forwards"): <--- Error
    input.z += 1
if Input.is_action_pressed("move_backwards"):
    input.z -= 1
if Input.is_action_pressed("move_left"):
    input.x += 1
if Input.is_action_pressed("move_right"):
    input.x -= 1

input = input.normalized()

vel.x = dir.x * moveSpeed
vel.y = dir.y * moveSpeed

vel.y -= gravity * delta

It says "unexpected token: "if""

in Engine by (16 points)
edited by

1 Answer

+1 vote

Note: I edited your post and clicked the "Code Sample" button to properly format your pasted code. Please make sure to do this in the future as it makes the code easier to read.

All the code after vel.z = 0 needs to be inside the _physics_process() function, which means it all needs to be indented. Code can't be executed outside of a function, which is why you get an "unexpected if"

by (22,191 points)

Thanks, I only started using Godot about a week ago.

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.