-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBullet.cs
36 lines (29 loc) · 870 Bytes
/
Bullet.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using Godot;
using System;
public class Bullet : Spatial
{
private const float bulletSpeed = 70f;
public float bulletDamage = 15f;
private const float killTimer = 4;
private float timer = 0;
private bool hitSomething = false;
public override void _Ready()
{
GetNode<Area>("Area").Connect("body_entered", this, "Collided");
}
public override void _PhysicsProcess(float delta) {
var forward = GlobalTransform.basis.z.Normalized();
GlobalTranslate(forward * bulletSpeed * delta);
timer += delta;
if (timer >= killTimer) {
QueueFree();
}
}
public void Collided(Godot.Object body) {
if (!hitSomething) {
body.EmitSignal("BulletHit", bulletDamage, GlobalTransform.origin);
hitSomething = true;
}
QueueFree();
}
}