Issue with the player direction

4.3

I built the script for the player model and im working on the passing and shooting


var player_model = $CharacterBody

var move_speed = 10

var teammate

var has_ball

var Vector3 direction = new Vector3


# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	
	
	
	
	pass # Replace with function body.

func passing():
	if has_ball:
		var target_player = nearest_teammate(direction)
		update_render(target_player)
		
		if animation.track_set_key_value(track, last_key, original_position) and Globals.ball != null and weakref(Globals.ball).get_ref():
			var a = phys_area.get_global_transform().origin
			var b = Globals.ball.get_global_transform().origin
			Globals.ball.set_linear_velocity((a-b)*10)
	
	

func shooting():
	if has_ball:
		target.looking_at(Globals.basket)
		if animation.track_set_key_value(track, last_key, original_position) and Globals.ball != null and weakref(Globals.ball).get_ref():
			var a = phys_area.get_global_transform().origin
			var b = Globals.ball.get_global_transform().origin
			Globals.ball.set_linear_velocity((a-b)*10)


func traversing():
	transform.position += direction * move_speed
	transform.looking_at(transform.position * direction)

func nearest_teammate():
	var closest_angle = teammate
	
	
	

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
	pass

I been using these two unity tutorials to work on the passing and shooting

but i cant shake the error here

var Vector3 direction = new Vector3

Expected end of statement after variable declaration, found “Identifier” instead.

It looks like you’re using a mix of C# style syntax in GDscript.
You’re trying to declare the type where you would name the variable, instead that would happen after you name the variable in between a : and =, like so: var direction: Vector3 = . Also Vector3 is a built in type so you would not need to use the new() method in this case so it would look something like var direction: Vector3 = Vector3(), you can set the property now if needed by filling in the parameter of the Vector3() method. If you need to change the value later you would access the values by referencing the property; direction.x = 1 etc.
New is a method for nodes so it would be called on the type you’re wanting to create a new instance of; var new_thing = Thing.new().

People more familiar with GDScript please correct me if I’m incorrect.

2 Likes