aboutsummaryrefslogtreecommitdiff
path: root/scripts/bullet.gd
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/bullet.gd')
-rw-r--r--scripts/bullet.gd39
1 files changed, 35 insertions, 4 deletions
diff --git a/scripts/bullet.gd b/scripts/bullet.gd
index 994d3d1..3716a4e 100644
--- a/scripts/bullet.gd
+++ b/scripts/bullet.gd
@@ -9,6 +9,8 @@ var timer = 0
var time_life = 3
var speed = 7
var hit_something = false
+var bounce = false
+var hitlist = []
func _ready():
_enemies_holder = get_tree().root.get_child(0).find_node("enemies")
@@ -16,8 +18,31 @@ func _ready():
func _physics_process(delta):
var forward_dir = -global_transform.basis.z.normalized()
- global_translate(forward_dir * speed * delta)
-
+ if bounce:
+ var space: PhysicsDirectSpaceState = get_world().direct_space_state
+ var from = transform.origin
+ var to = transform.origin + forward_dir * speed * delta
+ var mask = 0b0101
+ var result = space.intersect_ray(from, to, [], mask)
+ if result.size() > 0:
+ hitlist.clear()
+ var bounced = forward_dir.bounce(result.normal).normalized()
+ var z = -bounced;
+ var x = bounced.cross(result.normal).normalized();
+ var y = x.cross(z).normalized();
+ var basis = Basis(x, y, z);
+ global_transform.basis = basis
+ forward_dir = -global_transform.basis.z.normalized()
+ var dist = transform.origin.distance_to(result.position)
+ transform.origin = result.position
+ var amt = speed * delta - dist
+ global_translate(forward_dir * amt)
+ else:
+ global_translate(forward_dir * speed * delta)
+ else:
+ global_translate(forward_dir * speed * delta)
+
+
timer += delta
if timer >= time_life:
queue_free()
@@ -25,11 +50,17 @@ func _physics_process(delta):
func collided(body):
var parent = body.get_parent()
if parent == shooter: return
+ if parent in hitlist: return
if hit_something == false:
var groups = parent.get_groups()
if "enemies" in groups:
_enemies_holder.damage(parent.name, damage)
+
+
+ if !bounce:
+ hit_something = true
+ queue_free()
+ else:
+ hitlist.append(parent)
- hit_something = true
- queue_free()