using System.Collections.Generic; using Godot; using Godot.Collections; namespace Evolution.scripts; public partial class Box : Node3D { private RigidBody3D rb; private Vector3 rotation; private const double randomRange = 1; [Export] private Array numberLabels = new(); public override void _Ready() { rb = GetChild(0); rb.Position = new(GD.RandRange(-50, 50), GD.RandRange(50, 100), GD.RandRange(-50, 50)); rb.Rotation = new(GD.RandRange(-30, 30), GD.RandRange(-30, 30), GD.RandRange(-30, 30)); float mass =(float)GD.RandRange(0.1, 3); rb.Mass = mass; CollisionShape3D cs = rb.GetChild(0); cs.Scale = new(mass, mass, mass); rotation = new((float)GD.RandRange(-randomRange, randomRange), (float)GD.RandRange(-randomRange, randomRange), (float)GD.RandRange(-randomRange, randomRange)); rb.AddConstantTorque(rotation); foreach (Label3D numberLabel in numberLabels) { numberLabel.Text = $"{World.Instance.BoxCount}"; } } public override void _Process(double delta) { // Array collidingBodies = rb.GetCollidingBodies(); // if (collidingBodies.Count > 0) { // foreach (Node3D collidingBody in collidingBodies) { // GD.Print($"{collidingBody.Name}"); // World.Instance.Collisions++; // } // } if (rb.Position.Y < -50) { World.Instance.DestroyBox(); QueueFree(); } } }