fixed some things, broke others. gotta figure out more collision issues

This commit is contained in:
derek
2024-10-23 17:01:03 -05:00
parent d5300779a0
commit 8dd49b4d6b
4 changed files with 54 additions and 40 deletions

View File

@@ -13,8 +13,8 @@ var player_velocity
@onready var mesh = $Cylinder
@onready var particles = $GPUParticles3D
@onready var enemy_particles = $GPUParticlesEnemy
@onready var gunbullet1 = $gunbullet1/Cylinder
@onready var hit_indicator = $Audio/HitIndicator
@onready var ray: RayCast3D = $RayCast3D
# Called when the node enters the scene tree for the first time.
@@ -27,6 +27,8 @@ func _ready():
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _physics_process(delta):
angular_velocity = Vector3(0,0,0)
distance_from_player = abs(self.global_position - player_position)
if distance_from_player.x > 2 or distance_from_player.y > 2 or distance_from_player.z > 2:
@@ -35,36 +37,37 @@ func _physics_process(delta):
func _on_body_entered(body: Node) -> void:
if !body.is_in_group("player"):
if ray.is_colliding():
print("ray collision")
else:
print("no ray collision")
mesh.visible = false
#bullethole effect
#body.add_child(instance_bullethole)
#instance_bullethole.global_transform.origin = global_position
#if (abs(body.get_collision_normal().y) > 0.99):
#instance_bullethole.look_at(body.get_collision_point() + body.get_collision_normal(), Vector3(0,0,1))
#else:
#instance_bullethole.look_at(body.get_collision_point() + body.get_collision_normal())
##move rigidbodies
#if body.is_in_group("scene_rigidbody"):
#body.linear_velocity += transform.basis * Vector3(0,0,-1 * bullet_force_mod)
if body.is_in_group("breakable"):
var current_velocity = transform.basis * Vector3(0,0,-1 * bullet_force_mod)
body.breaking(current_velocity)
if body.is_in_group("enemy_target"):
print("enemy target hit")
hit_indicator.play()
enemy_particles.emitting = true
body.hit(bullet_damage)
if 1>2:#ray.is_colliding() and !ray.get_collider().is_in_group("player"):
#Bullet Hole Effect
ray.get_collider().add_child(instance_bullethole)
instance_bullethole.global_transform.origin = ray.get_collision_point()
if (abs(ray.get_collision_normal().y) > 0.99):
instance_bullethole.look_at(ray.get_collision_point() + ray.get_collision_normal(), Vector3(0,0,1))
else:
instance_bullethole.look_at(ray.get_collision_point() + ray.get_collision_normal())
if body.is_in_group("switch"):
body.hit()
#Break Breakable Objects
if ray.get_collider().is_in_group("breakable"):
var current_velocity = transform.basis * Vector3(0,0,-1 * bullet_force_mod)
ray.get_collider().breaking(current_velocity)
#Hit Enemies
if ray.get_collider().is_in_group("enemy_target"):
hit_indicator.play()
enemy_particles.emitting = true
ray.get_collider().hit(bullet_damage)
#Switch Switches
if ray.get_collider().is_in_group("switch"):
ray.get_collider().hit()
#await get_tree().create_timer(1.0).timeout
queue_free()

View File

@@ -153,6 +153,7 @@ func fire(delta):
instance_bullet.random_spread_amt = random_spread_amt
instance_bullet.bullet_force_mod = bullet_force_mod
instance_bullet.player_position = player.global_position
instance_bullet.player_velocity = player.velocity
instance_bullet.instance_bullethole = bullethole.instantiate()
get_tree().get_root().add_child(instance_bullet)
player.recoil.add_recoil(recoil_amount)