made bullet with a camera on the end. other tweaks
This commit is contained in:
@@ -12,6 +12,7 @@ var distance_from_player
|
||||
var player_position
|
||||
var player_velocity
|
||||
var bullet_active = true
|
||||
var bullet_target : Node
|
||||
|
||||
@onready var mesh = $Cylinder
|
||||
@onready var particles = $GPUParticles3D
|
||||
@@ -23,47 +24,85 @@ var bullet_active = true
|
||||
func _ready():
|
||||
|
||||
visible = false
|
||||
linear_velocity += transform.basis * Vector3(0, 0, -bullet_speed) + player_velocity
|
||||
if bullet_target == null:
|
||||
linear_velocity += transform.basis * Vector3(0, 0, -bullet_speed) + player_velocity
|
||||
|
||||
# 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)
|
||||
distance_from_player = self.global_position.distance_to(player_position)
|
||||
|
||||
if distance_from_player.length() > 1.5:
|
||||
if distance_from_player > 1.5:
|
||||
visible = true
|
||||
|
||||
|
||||
if bullet_target != null:
|
||||
linear_velocity = transform.basis * Vector3(0, 0, -bullet_speed)
|
||||
look_at(bullet_target.global_position)
|
||||
|
||||
if ray.is_colliding():
|
||||
var body = ray.get_collider()
|
||||
if body != null and !body.is_in_group("player"):
|
||||
|
||||
mesh.visible = false
|
||||
ray.enabled = false
|
||||
|
||||
if body.is_in_group("enemy_target"):
|
||||
hit_indicator.play()
|
||||
enemy_particles.emitting = true
|
||||
SignalBus.emit_signal("enemy_hit")
|
||||
ray.get_collider().hit(bullet_damage)
|
||||
|
||||
#bullethole effect
|
||||
body.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()
|
||||
|
||||
#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)
|
||||
ray.get_collider().breaking(current_velocity)
|
||||
|
||||
despawn()
|
||||
|
||||
func _on_body_entered(body: Node) -> void:
|
||||
|
||||
if !body.is_in_group("player"):
|
||||
|
||||
ray.enabled = false
|
||||
|
||||
if ray.is_colliding():
|
||||
var ray_body = ray.get_collider()
|
||||
if ray_body != null:
|
||||
#bullethole effect
|
||||
ray_body.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()
|
||||
|
||||
##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)
|
||||
despawn()
|
||||
#func _on_body_entered(body: Node) -> void:
|
||||
#
|
||||
#if !body.is_in_group("player"):
|
||||
#
|
||||
#ray.enabled = false
|
||||
#
|
||||
#if ray.is_colliding():
|
||||
#var ray_body = ray.get_collider()
|
||||
#if ray_body != null:
|
||||
##bullethole effect
|
||||
#ray_body.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()
|
||||
#
|
||||
###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)
|
||||
#despawn()
|
||||
|
||||
func despawn():
|
||||
#visible = false
|
||||
|
||||
Reference in New Issue
Block a user