28 lines
778 B
C#
28 lines
778 B
C#
using Godot;
|
|
using System;
|
|
[GlobalClass]
|
|
public partial class Asteroid : Node3D {
|
|
[Export] private float speed;
|
|
[Export] private float size;
|
|
[Export] private float rotSpeed = 100f;
|
|
private Vector3 rotation;
|
|
|
|
public override void _Ready() {
|
|
size = GD.Randf();
|
|
speed = GD.Randf() * 5f;
|
|
|
|
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;
|
|
if (Position.Z > 7) {
|
|
GD.Print($"Asteroid {Name} below screen!");
|
|
QueueFree();
|
|
}
|
|
}
|
|
}
|