|
|
|
|
@ -4,6 +4,7 @@ namespace Scripts;
|
|
|
|
|
[GlobalClass]
|
|
|
|
|
public partial class Asteroid : Node3D {
|
|
|
|
|
[Export] private RigidBody3D asteroidRb;
|
|
|
|
|
[Export] private MeshInstance3D asteroidMesh;
|
|
|
|
|
|
|
|
|
|
private float speed;
|
|
|
|
|
private float rotSpeed = 100f;
|
|
|
|
|
@ -13,28 +14,32 @@ public partial class Asteroid : Node3D {
|
|
|
|
|
public override void _Ready() {
|
|
|
|
|
size = GD.Randf();
|
|
|
|
|
asteroidRb.Mass = size;
|
|
|
|
|
speed = GD.Randf() * 5f;
|
|
|
|
|
speed = GD.Randf() * 5f + 1f;
|
|
|
|
|
|
|
|
|
|
Scale = new(size, size,size);
|
|
|
|
|
asteroidRb.Scale = new(size, size,size);
|
|
|
|
|
asteroidMesh.Scale = new(size, size,size);
|
|
|
|
|
|
|
|
|
|
rotation = new((float)GD.RandRange(-rotSpeed, rotSpeed), (float)GD.RandRange(-rotSpeed, rotSpeed), (float)GD.RandRange(-rotSpeed, rotSpeed));
|
|
|
|
|
Position = new((float)GD.RandRange(-3.7, 3.7), 0, -6.4f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void _Process(double delta) {
|
|
|
|
|
// Position += new Vector3(0, 0, speed * (float)delta);
|
|
|
|
|
RotationDegrees += rotation * (float)delta;
|
|
|
|
|
|
|
|
|
|
// RotationDegrees += rotation * (float)delta;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void _PhysicsProcess(double delta) {
|
|
|
|
|
KinematicCollision3D collision = asteroidRb.MoveAndCollide(new Vector3(0, 0, speed * (float)delta));
|
|
|
|
|
asteroidRb.Rotate(rotation.Normalized(), (float)delta);
|
|
|
|
|
|
|
|
|
|
KinematicCollision3D collision = asteroidRb.MoveAndCollide(new(0, 0, speed * (float)delta));
|
|
|
|
|
if (collision?.GetCollider() is Node3D collider) {
|
|
|
|
|
GD.Print($"{Name} collides with {collider.GetParentNode3D().Name}");
|
|
|
|
|
if (collider is Asteroid asteroid) asteroid.Explode();
|
|
|
|
|
Explode();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Position.Z > 7) {
|
|
|
|
|
//TODO: Change into collision with outer box
|
|
|
|
|
if (Position.Z >= 6.4f) {
|
|
|
|
|
GD.Print($"Asteroid {Name} below screen!");
|
|
|
|
|
Explode();
|
|
|
|
|
}
|
|
|
|
|
|