Expected end of statement after variable declaration, found "."

Godot Version

4.2.1 Stable

I dont understand whats mean by “Line 40:Expected end of statement after variable declaration, found “.” instead.”

Im trying to make Sony PS1 controller with right stick to look around on Godot 4.
Here’s the errors.

Line 40:Identifier “cameraAnchor” not declared in the current scope.
Line 40:Identifier “camera_velocity” not declared in the current scope.
Line 40:Function “deg2rad()” not found in base self. Did you mean to use “deg_to_rad()”?
Line 41:Identifier “cameraAnchor” not declared in the current scope.
Line 41:Identifier “camera_velocity” not declared in the current scope.
Line 41:Function “deg2rad()” not found in base self. Did you mean to use “deg_to_rad()”?
Line 43:Identifier “cameraAnchor” not declared in the current scope.
Line 43:Identifier “cameraAnchor” not declared in the current scope.
Line 43:Function “deg2rad()” not found in base self. Did you mean to use “deg_to_rad()”?
Line 43:Function “deg2rad()” not found in base self. Did you mean to use “deg_to_rad()”?
Line 48:Identifier “JOY_AXIS_2” not declared in the current scope.
Line 57:Identifier “JOY_AXIS_3” not declared in the current scope.
Line 65:Identifier “camera” not declared in the current scope.

Its kept appearing this on under func_process(delta):


Seems like you partially copied a Godot 3.x script

  • cameraAnchor is not a variable
  • camera_velocity is not a variable, same as above.
  • deg2rad has been replaced with deg_to_rad in godot 4.x
  • JOY_AXIS_2 and JOY_AXIS_3 are better left to the InputMap in your project settings. Use actions instead of direct input manipulation.
  • emit_signal(camera): camera not declared, you can probaby delete this entire line, no reason to emit every frame.

Some more errors that will occur once the basic syntax is fixed

  • Line 40 you mean to use function rotate_y(), with a underscore instead of a peroid.
  • Line 41 you mean to use rotation.x since you are modifying the rotation property instead of using the rotate function
2 Likes

I finally did it. The Right Stick on Controller works with look around the Game, but the character isn’t moving and the camera rotating on its own. I dont know whats cause it??
THe left stick should be work since I already inputed all direction in Project Setting as same with Keyboard WASD.







Make sure to paste code instead of taking screen shots

```
type or paste code here
```


Again better to use actions for the camera inputs, seems like you have Input.get_vector("left", "right", "backward", "forward") for direction, why not make a similar line and actions for the camera?

Again better to use actions for the camera inputs, seems like you have Input.get_vector(“left”, “right”, “backward”, “forward”) for direction, why not make a similar line and actions for the camera?

Its have action, so where I should put em and how to stop rotating?

extends CharacterBody3D

@export var player: CharacterBody3D
@export var sensitivity := 1

@onready var CameraPivot = $CameraPivot
@onready var animation_player = $AnimationPlayer
@onready var visuals = $visuals

const SPEED = 60
const JUMP_VELOCITY = 80
const JOY_DEADZONE = 0.2
const JOY_AXIS_RESCALE = 1.0/(1.0-JOY_DEADZONE)
const JOY_ROTATION_MULTIPLIER = 200.0 * PI / 180.0

@export var sens_horizontal = 7
@export var sens_vertical = 7

# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
var lookat
var lastLookAtDirection : Vector3

func _ready():
		var camera = get_node("CameraPivot/Camera3D")
	
		lookat = get_tree().get_nodes_in_group("ControllerPlayerAnimate")[0].get_node("LookAt")
		player = get_tree().get_nodes_in_group("Player")[0]
	
		Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
		pass
	
func _input(event):
	if event is InputEventMouseMotion:
		rotate_y(deg_to_rad(-event.relative.x*sens_horizontal))
		visuals.rotate_y(deg_to_rad(event.relative.x*sens_horizontal))
		CameraPivot.rotate_x(deg_to_rad(event.relative.y*sens_vertical))
		
func _process(delta):
		rotate_y 
		rotate_x 

		rotation.x =clamp(rotation.x,deg_to_rad(-80),deg_to_rad(80))

		if Input.get_connected_joypads().size() == 0:
			return
		
		var xAxis = Input.get_joy_axis(0, JOY_AXIS_RIGHT_X)
		if abs(xAxis) > JOY_DEADZONE:

			if xAxis >0:
				xAxis = (xAxis-JOY_DEADZONE) * JOY_AXIS_RESCALE
		else:
			xAxis = (xAxis+JOY_DEADZONE) * JOY_AXIS_RESCALE
		rotate_object_local(Vector3.UP, -xAxis * delta * JOY_ROTATION_MULTIPLIER)
		
		var yAxis = Input.get_joy_axis(0, JOY_AXIS_RIGHT_Y)
		if abs(yAxis) > JOY_DEADZONE:
			if yAxis >0:
				yAxis = (yAxis-JOY_DEADZONE) * JOY_AXIS_RESCALE
		else:
			yAxis = (yAxis+JOY_DEADZONE) * JOY_AXIS_RESCALE
		CameraPivot.rotate_object_local(Vector3.RIGHT, -yAxis * delta * JOY_ROTATION_MULTIPLIER/2)
		CameraPivot.rotation.x = clamp(CameraPivot.rotation.x, -1.0, 1.0)
		
		global_position = player.global_position
		$CameraPivot/Camera3D.look_at(player.get_node("LookAt").global_position)
		pass
	
	
		if not is_on_floor():
			velocity.y -= gravity * delta
	# Handle jump.
		if Input.is_action_just_pressed("ui_accept") and is_on_floor():
			velocity.y = JUMP_VELOCITY

	
	# Get the input direction and handle the movement/deceleration.
	# As good practice, you should replace UI actions with custom gameplay actions.
		var input_dir = Input.get_vector("right", "left", "backward", "forward")
		var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
		if direction:
		
			velocity.x = move_toward(velocity.x, 0, SPEED)
			velocity.z = move_toward(velocity.z, 0, SPEED)
			
			if animation_player.current_animation != "Idle_Amy":
				animation_player.play("Idle_Amy")
		
		visuals.look_at(position + direction)

		velocity.z = direction.z * SPEED
		velocity.x = direction.x * SPEED
		
			
		if animation_player.current_animation != "Amy_Walking":
			animation_player.play("Amy_Walking")

		$AnimationTree.set("parameters/conditions/idle_Amy", input_dir == Vector2.ZERO && is_on_floor())
		$AnimationTree.set("parameters/conditions/Amy_Walking", input_dir != Vector2.ZERO && is_on_floor())
		$AnimationTree.set("parameters/conditions/Run", input_dir != Vector2.ZERO && is_on_floor())
		$AnimationTree.set("parameters/conditions/Walk_Strife_Amy", input_dir != Vector2.ZERO && is_on_floor())
	
		move_and_slide()

All of this can be replaced by get_vector

var look_direction := Input.get_vector("look_left", "look_right", "look_up", "look_down")

Then you can use this variable to apply rotation.

rotate_y(-look_direction.x * delta * JOY_ROTATION_MULTIPLIER)
CameraPivot.rotate_x(-look_direction.y * delta * JOY_ROTATION_MULTIPLIER/2)

I notice you are extending CharacterBody3D, but have a var player, is this script attached to your player?


On pasting code the </> button or ctrl+e in the forum will generate the three ticks for you like so

```
    type or paste code here
```

is formatted to ↓

    type or paste code here