35 lines
1.0 KiB
C#
35 lines
1.0 KiB
C#
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<RigidBody3D>(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<CollisionShape3D>(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<CsgBox3D>(0).GetChild<Label3D>(0);
|
|
numberLabel.Text = $"{World.Instance.BoxCount}";
|
|
}
|
|
|
|
public override void _Process(double delta) {
|
|
if (rb.Position.Y < -50) {
|
|
World.Instance.DestroyBox();
|
|
QueueFree();
|
|
}
|
|
}
|
|
} |