Invalid set index 'z' (on base: 'Vector2') with value of type 'float'.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ragacakaci
extends KinematicBody


const MOUSE_SENSITIVITY = 0.1


var puppet_position = Vector3()
var puppet_velocity = Vector3()
var puppet_rotation = Vector2()


export (NodePath) onready var head = get_node(head) as Spatial
export (NodePath) onready var model = get_node(model) as MeshInstance
export (NodePath) onready var network_tick_rate = get_node(network_tick_rate) as Timer
export (NodePath) onready var movment_tween = get_node(movment_tween) as Tween



onready var camera = $head/Camera
onready var meleee_anim = $AnimationPlayer
onready var melee_anim = $AnimationPlayer
onready var hitbox = $head/Camera/Hitbox  
onready var ult_anim = $AnimationPlayer
var melee_damage = 34
var meleee_damage = 23
var ult_damage = 200


var hp = 100 
var velocity = Vector2(0, 0)

var current_vel = Vector3.ZERO
var dir = Vector3.ZERO

const SPEED = 10
const SPRINT_SPEED = 30
const ACCEL = 20.0

# Jump
const GRAVITY = -40.0
const JUMP_SPEED = 15
var jump_counter = 0
const AIR_ACCEL = 9.0


func _ready():
	Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
	
	camera.current =  is_network_master()
	model.visible =  !is_network_master()
	get_tree().connect("network_peer_connected", self, "_network_peer_connected")

func _process(delta):
	window_activity()
	melee()
	meleee()
	ult()
	_physics_process(delta)
	is_network_master()
	_on_NetworkTickBate_timeout()




func _physics_process(delta):
	
	
	
	dir = Vector3.ZERO
	
	if Input.is_action_pressed("forward"):
		dir -= camera.global_transform.basis.z
	if Input.is_action_pressed("backward"):
		dir += camera.global_transform.basis.z
	if Input.is_action_pressed("right"):
		dir += camera.global_transform.basis.x
	if Input.is_action_pressed("left"):
		dir -= camera.global_transform.basis.x
	
	# Normalizing the input directions
	dir = dir.normalized()
	
	velocity.y += GRAVITY * delta
	
	if is_on_floor():
		jump_counter = 0
	
	# Jump
	if Input.is_action_just_pressed("jump") and jump_counter < 3:
		jump_counter += 1
		velocity.y = JUMP_SPEED


	if is_network_master():
		var speed = SPRINT_SPEED if Input.is_action_pressed("sprint") else SPEED
		var target_vel = dir * speed
		var accel = ACCEL if is_on_floor() else AIR_ACCEL
		current_vel = current_vel.linear_interpolate(target_vel, accel * delta)
		velocity.x = current_vel.x
		velocity.z = current_vel.z
	
	else:
		
		
		global_transform.origin = puppet_position
		velocity.x = puppet_velocity.x  problemd here    here shows sum thingi i dont knwo what its called
		velocity.z = puppet_velocity.z or here idk sorry
		
		rotation.y =  puppet_rotation.y
		head.rotation.x = puppet_rotation.x
		
	if !movment_tween.is_active():
		velocity = move_and_slide(velocity, Vector3.UP, true, 4, deg2rad(45))

puppet func update_state(p_position, p_velocity, p_rotation):
	puppet_position = p_position
	puppet_velocity = p_velocity
	puppet_rotation = p_rotation
	
	movment_tween.interpolate_property(self, "global_transform", global_transform, Transform(global_transform.basis, p_position), 0.1)
	movment_tween.start()


func _on_NetworkTickBate_timeout():
	if is_network_master():
		rpc_unreliable("update_state", global_transform.origin, velocity, Vector2(head.rotation.x, rotation.y))
	else:
		network_tick_rate.stop()




func _input(event):
	if is_network_master():
		if event is InputEventMouseMotion:
			$head.rotate_x(deg2rad(event.relative.y * MOUSE_SENSITIVITY * -1))
			$head.rotation_degrees.x = clamp($head.rotation_degrees.x, -40, 40)
			self.rotate_y(deg2rad(event.relative.x * MOUSE_SENSITIVITY * -1))




func melee():
	if Input.is_action_just_pressed("fire"):
		if not melee_anim.is_playing():
			melee_anim.play("Attack")
			melee_anim.queue("Return")
		if melee_anim.current_animation == "Attack":
			for body in hitbox.get_overlapping_bodies():
				if body.is_in_group("enemy"):
					body.health -= melee_damage
   
func meleee():
	if Input.is_action_just_pressed("fire2"):
		if not melee_anim.is_playing():
			melee_anim.play("aattack")
			melee_anim.queue("rreturn")
		if melee_anim.current_animation == "aattack":
			for body in hitbox.get_overlapping_bodies():
				if body.is_in_group("enemy"):
					body.health -= meleee_damage
	
	
func ult():
	if Input.is_action_just_pressed("ult"):
		if not melee_anim.is_playing():
			melee_anim.play("ultt")
			melee_anim.queue("ult")
		if melee_anim.current_animation == "ultt":
			for body in hitbox.get_overlapping_bodies():
				if body.is_in_group("enemy"):
					body.health -= ult_damage
	

func window_activity():
	if Input.is_action_just_pressed("ui_focus_next"):
		if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
			Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
		else:
			Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)

making 3d sword game multimplayer and there is problem can i get help??

Edited to fix code formatting…

jgodfrey | 2023-01-10 20:22

:bust_in_silhouette: Reply From: jgodfrey

You’re trying to reference a .z component in your velocity variable - which is defined as a Vector2 and therefore has no z component. For instance, in these places…

velocity.z = current_vel.z

and

velocity.z = puppet_velocity.z

Assuming you’re working in 3D (and you seem to be), you probably want to change this:

var velocity = Vector2(0, 0)

to…

var velocity = Vector3.ZERO

jgodfrey | 2023-01-10 20:26