Rockt lancher works with direct hits only

This commit is contained in:
unfa 2022-01-01 02:42:10 +01:00
parent dd924f53de
commit 5dbc840ef4
3 changed files with 57 additions and 23 deletions

View file

@ -5,14 +5,17 @@ extends Node3D
@export var damage : int
var source_position : Vector3
var player
var noise = OpenSimplexNoise.new()
var time := 0.0
#var active := true
@onready var halo = $OmniLight3D/Halo
@onready var halo_transform = halo.global_transform
@export var halo_color : Color
var ray_previously : bool
var ray_previously : bool = false
# Declare member variables here. Examples:
# var a = 2
@ -21,6 +24,9 @@ var ray_previously : bool
# Called when the node enters the scene tree for the first time.
func _ready():
var halo_material = halo.mesh.surface_get_material(0).duplicate()
halo.mesh.surface_set_material(0, halo_material)
#$OmniLight3D/Smoke.emitting = true
noise.octaves = 2
@ -36,20 +42,24 @@ func _physics_process(delta):
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
time += delta
var flicker = sin(time * 225) + sin(time * 240) / 2 + sin(time * 295) / 3
$OmniLight3D.light_energy = 3 + flicker /2
halo.mesh.size = Vector2.ONE * 2 + Vector2(flicker, flicker) / 16
halo.mesh.size = Vector2.ONE * 1.5 + Vector2(flicker, flicker) / 16
var space_state = get_world_3d().direct_space_state
var physics_ray_query_parameters_3d = PhysicsRayQueryParameters3D.new()
physics_ray_query_parameters_3d.from = halo.global_transform.origin
physics_ray_query_parameters_3d.to = get_viewport().get_camera_3d().global_transform.origin
physics_ray_query_parameters_3d.exclude = [self]
physics_ray_query_parameters_3d.exclude = [$Area3D, get_viewport().get_camera_3d().get_parent().get_parent()]
var ray = space_state.intersect_ray(physics_ray_query_parameters_3d)
#print(ray)
if ray.size() > 0 and not ray_previously:
halo.hide()
elif not ray.size() > 0 and ray_previously:
@ -59,32 +69,48 @@ func _process(delta):
ray_previously = true
else:
ray_previously = false
if halo.visible:
var fade = 1 - clamp((physics_ray_query_parameters_3d.from.distance_squared_to(physics_ray_query_parameters_3d.to) / 1000 ), 0, 1)
#print(fade)
halo.mesh.surface_get_material(0)["albedo_color"] = halo_color * fade
func give_damage(target: Node, hit_position: Vector3, hit_normal: Vector3, damage: int, source_position: Vector3, type: Globals.DamageType, push: float):
if target.has_method(&'take_damage'): # we've hit a player or something else - the ywill handle everything like effects etc.
target.rpc(&'take_damage', get_multiplayer_authority(), hit_position, hit_normal, damage, source_position, type, push)
else:
target.rpc(&'take_damage',get_multiplayer_authority(), hit_position, hit_normal, damage, source_position, type, push)
# TODO take data from the material of the target and spawn an appropriate hit effect
var hit_effect : Node = hit_effect_scene.instantiate()
get_tree().root.add_child(hit_effect)
hit_effect.global_transform.origin = hit_position
#print(impact_vfx.global_transform)
var result = hit_effect.look_at(hit_position + hit_normal)
if not result: # if the look_at failed (as it will on floors and ceilings) try another approach:
hit_effect.look_at(hit_position + hit_normal, Vector3.LEFT)
hit_effect.rotate(hit_normal, randf_range(0, PI * 2))
var hit_effect : Node = hit_effect_scene.instantiate()
get_tree().root.add_child(hit_effect)
hit_effect.global_transform.origin = hit_position
#print(impact_vfx.global_transform)
var result = hit_effect.look_at(hit_position + hit_normal)
if not result: # if the look_at failed (as it will on floors and ceilings) try another approach:
hit_effect.look_at(hit_position + hit_normal, Vector3.LEFT)
hit_effect.rotate(hit_normal, randf_range(0, PI * 2))
#print(impact_vfx.global_transform)
func _on_Area3D_body_entered(body):
var hit_normal = body.global_transform.origin - global_transform.origin # is this correct?
give_damage(body, global_transform.origin, hit_normal,damage, source_position, Globals.DamageType.EXPLOSION, 100)
queue_free()
if is_multiplayer_authority(): # only do this on the attacker's local instance of the game
var hit_normal = body.global_transform.origin - global_transform.origin # is this correct?
give_damage(body, global_transform.origin, hit_normal,damage, source_position, Globals.DamageType.EXPLOSION, 100)
set_process(false)
halo.hide()
$OmniLight3D.light_energy = 0
$OmniLight3D/Smoke.emitting = false
$Area3D.queue_free()
$Rocket.queue_free()
$Timer2.start()
func _on_Timer_timeout():
queue_free()
func _on_Timer2_timeout():
queue_free()

View file

@ -80,13 +80,15 @@ fill_to = Vector2(0.5, 0)
blend_mode = 1
no_depth_test = true
shading_mode = 0
vertex_color_use_as_albedo = true
albedo_color = Color(1, 0.529412, 0.270588, 1)
albedo_texture = SubResource( "GradientTexture2D_5y8sa" )
disable_receive_shadows = true
billboard_mode = 1
fixed_size = true
point_size = 89.7
proximity_fade_distance = 0.5
proximity_fade_enable = true
proximity_fade_distance = 0.25
[sub_resource type="QuadMesh" id="QuadMesh_q2732"]
material = SubResource( "StandardMaterial3D_yhx2h" )
@ -96,6 +98,7 @@ script = ExtResource( "1_3ywpo" )
hit_effect_scene = ExtResource( "2_1tben" )
speed = 35.0
damage = 75
halo_color = Color(1, 0.529412, 0.270588, 1)
[node name="Rocket" parent="." instance=ExtResource( "3_wqrr6" )]
transform = Transform3D(-1.07092e-07, 0, -2.44998, 0, 2.44998, 0, 2.44998, 0, -1.07092e-07, 0, 0, -0.28679)
@ -143,7 +146,6 @@ process_material = SubResource( "ParticlesMaterial_mu7mc" )
draw_pass_1 = SubResource( "QuadMesh_gkbg3" )
[node name="Halo" type="MeshInstance3D" parent="OmniLight3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.1)
layers = 2
cast_shadow = 0
mesh = SubResource( "QuadMesh_q2732" )
@ -155,7 +157,12 @@ wait_time = 10.0
one_shot = true
autostart = true
[node name="Timer2" type="Timer" parent="."]
wait_time = 2.0
one_shot = true
[connection signal="body_entered" from="Area3D" to="." method="_on_Area3D_body_entered"]
[connection signal="timeout" from="Timer" to="." method="_on_Timer_timeout"]
[connection signal="timeout" from="Timer2" to="." method="_on_Timer2_timeout"]
[editable path="Rocket"]

View file

@ -119,6 +119,7 @@ var spread = spread_min
var projectile_instance = projectile_or_tracer_scene.instantiate()
projectile_instance.global_transform = muzzle.global_transform.looking_at(to)
projectile_instance.source_position = player.global_transform.origin
projectile_instance.player = player
#projectile_instance.get_node("RayCast3D").add_exception(player)
#projectile_instance.rotate_x(PI/2)
get_tree().root.add_child(projectile_instance)