pieces can rotate while moving

whe can color pieces dynamically

pieces have collider and can kill each other
This commit is contained in:
francis 2026-03-06 22:46:34 +01:00
parent 3ea7bfd5dc
commit 026d634c3a
18 changed files with 283 additions and 263 deletions

View file

@ -4,18 +4,21 @@ extends Node3D
@export var piece_res : PieceRes
var is_moving : bool = false
var is_rotating: bool = false
var rotation_target: Vector3
var target : Vector2
var start_pos :Vector3
var start_coord: Vector2i
var mesh_instance_3d: MeshInstance3D
var possible_movements: Array[Vector2i]
#@export var color : StandardMaterial3D = preload("uid://brrbuo0i0e5bh") as StandardMaterial3D:
#set(material):
#color = material
#if Engine.is_editor_hint():
#mesh.material_override = color
#get:
#return color
@export var team: String = "us"
const PIECE_WHITE = preload("uid://brrbuo0i0e5bh")
const PIECE_RED = preload("uid://bekkxcgjt3hct")
const PIECE_BLACK = preload("uid://bxg7bjgiqfnru")
@onready var attack_area_3d: Area3D = $AttackArea3D
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
for rule in piece_res.rules:
@ -23,9 +26,15 @@ func _ready() -> void:
print(piece_res.material)
var mesh_instance = MeshInstance3D.new()
mesh_instance.mesh = piece_res.mesh
mesh_instance.mesh.surface_set_material(0,piece_res.material)
add_child(mesh_instance)
mesh_instance_3d = mesh_instance
if team == "us":
add_to_group("PlayerPieces")
mesh_instance_3d.material_override = PIECE_WHITE
if team == "them":
print("dadwdawf<sef")
add_to_group("Enemy")
mesh_instance_3d.material_override = PIECE_RED
start_coord = to_coord()
@ -56,7 +65,11 @@ func _process(delta: float) -> void:
if position.z == target.y and position.x == target.x:
is_moving = false
pass
if is_rotating:
if rotation_target == rotation:
is_moving = true
pass
pass
func move_to(new_target: Vector2):
@ -66,12 +79,33 @@ func move_to(new_target: Vector2):
#possible_movements = [Vector2i(0,1)]
target = new_target * 2
start_pos = position
#var angle = atan2((position.z - target.y),(position.x- target.x))
#rotation.y = angle
#rotate_y(angle)
look_at(Vector3(target.x,0,target.y), Vector3.UP)
is_moving = true
pass
func rotate_to(new_rotation: Vector3):
is_rotating = true
rotation_target = new_rotation
pass
func to_coord() -> Vector2i:
return Vector2i(position.x / 2, position.z / 2)
return Vector2i(position.x / 2., position.z / 2.)
func die():
queue_free()
pass
func _on_attack_area_3d_body_entered(body: Node3D) -> void:
if body == self:
return
print("body entered")
if body.is_moving:
self.queue_free()
if is_moving:
body.queue_free()
pass # Replace with function body.