using System; using Godot; namespace Evolution.scripts; public partial class Box : Node3D { private RigidBody3D rb; private Vector3 rotation; private const double randomRange = 1; 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); Label3D numberLabel = cs.GetChild(0).GetChild(0); numberLabel.Text = $"{World.Instance.BoxCount}"; } public override void _Process(double delta) { if (rb.Position.Y < -50) { World.Instance.DestroyBox(); QueueFree(); } } }