diff options
| author | Anson Bridges <bridges.anson@gmail.com> | 2022-09-25 06:39:12 -0400 |
|---|---|---|
| committer | Anson Bridges <bridges.anson@gmail.com> | 2022-09-25 06:39:12 -0400 |
| commit | 7a1d857de96174dfa5a0fa40f8c14acbd2f651c2 (patch) | |
| tree | d52acaa4e89b0f8375326ea1aefd0105bb91cfc7 /godot/scenes/weapons | |
| parent | 62039380a67b6da396d1c8d745d2e2625ba988fc (diff) | |
weapons, viewmodels, some performance fixes
Diffstat (limited to 'godot/scenes/weapons')
| -rw-r--r-- | godot/scenes/weapons/hands.gd | 46 | ||||
| -rw-r--r-- | godot/scenes/weapons/hands.res | bin | 0 -> 173 bytes | |||
| -rw-r--r-- | godot/scenes/weapons/pistol.gd | 64 | ||||
| -rw-r--r-- | godot/scenes/weapons/pistol.tres | 7 | ||||
| -rw-r--r-- | godot/scenes/weapons/pistol.tscn | 146 | ||||
| -rw-r--r-- | godot/scenes/weapons/rockets.gd | 68 | ||||
| -rw-r--r-- | godot/scenes/weapons/rockets.tres (renamed from godot/scenes/weapons/w_Rockets.tscn) | 5 | ||||
| -rw-r--r-- | godot/scenes/weapons/rockets.tscn | 71 |
8 files changed, 376 insertions, 31 deletions
diff --git a/godot/scenes/weapons/hands.gd b/godot/scenes/weapons/hands.gd new file mode 100644 index 0000000..567ff85 --- /dev/null +++ b/godot/scenes/weapons/hands.gd @@ -0,0 +1,46 @@ +extends Resource + +var player_owner: RigidBody = null +const fist_damage: int = 15 +var can_swing: bool = true +var blocking: bool = false + +const name: String = "HANDS" + +func init(owner): + player_owner = owner + +func deselect() -> bool: + if can_swing and !blocking: + return true + return false + +func select() -> void: + player_owner.rpc("anim_event", {"VMANIMPLAY" : "humanidle"}) + +func attack1(): + if !can_swing or blocking: + return + can_swing = false + player_owner.rpc("anim_event", {"VMANIMPLAY" : "humanpunch"}) + yield(player_owner.get_tree().create_timer(0.45), "timeout") + if player_owner.melee_ray.is_colliding(): + var hit = player_owner.melee_ray.get_collider() + player_owner.rpc("play_weapon_sound", "res://sounds/punch_generic.wav") + if hit.has_method("damage"): + hit.rpc("damage", fist_damage, "BLUNT", [player_owner.get_network_master(), player_owner.name], "using fists") + if hit.has_method("net_apply_impulse"): + hit.rpc("net_apply_impulse", -100*player_owner.melee_ray.global_transform.basis.z) + yield(player_owner.get_tree().create_timer(0.55), "timeout") + can_swing = true + +func mouse_input(_m1: float, _m3: float, m2: float) -> void: + if m2 > 0 and !blocking and can_swing: + blocking = true + player_owner.rpc("anim_event", {"VMANIMPLAY" : "raise_fists"}) + elif blocking and m2 == 0: + blocking = false + player_owner.rpc("anim_event", {"VMANIMPLAY" : "lower_fists"}) + +func can_pickup() -> bool: + return !blocking and can_swing diff --git a/godot/scenes/weapons/hands.res b/godot/scenes/weapons/hands.res Binary files differnew file mode 100644 index 0000000..e00284f --- /dev/null +++ b/godot/scenes/weapons/hands.res diff --git a/godot/scenes/weapons/pistol.gd b/godot/scenes/weapons/pistol.gd new file mode 100644 index 0000000..219696b --- /dev/null +++ b/godot/scenes/weapons/pistol.gd @@ -0,0 +1,64 @@ +extends Resource + +var player_owner: RigidBody = null +const bullet_damage: int = 35 +var can_fire: bool = true +var pistol_scene: Spatial = null +var reloading: bool = false + +const name: String = "PISTOL" +const trfrm = Transform(Vector3(-0.476,2.762,-0.515), Vector3(-1.095,0.299,2.614), Vector3(2.588,0.634,1.011),Vector3(-0.232,0.644,0.006)) + +func _init(): + pistol_scene = preload("res://scenes/weapons/pistol.tscn").instance() + pistol_scene.set_visible(false) + +func init(owner): + player_owner = owner + player_owner.add_weapon_vm(pistol_scene, trfrm) + +func select() -> void: + if can_fire: pistol_scene.get_node("AnimationPlayer").play("idle") + player_owner.rpc("anim_event", {"VMANIMPLAY" : "pistol_idle_vm"}) + pistol_scene.set_visible(true) + +func deselect() -> bool: + if reloading: + return false + pistol_scene.set_visible(false) + return true + +func reload() -> void: + if can_fire or reloading: + return + reloading = true + player_owner.rpc("anim_event", {"VMANIMPLAY" : "pistol_reload_vm"}) + pistol_scene.get_node("PistolReload").play() + yield(player_owner.get_tree().create_timer(2.7), "timeout") + pistol_scene.get_node("AnimationPlayer").play("reset") + can_fire = true + reloading = false + +func attack1(): + if !can_fire: + return + can_fire = false + + pistol_scene.get_node("AnimationPlayer").play("fire") + player_owner.rpc("anim_event", {"VMANIMPLAY" : "pistol_fire_vm"}) + yield(player_owner.get_tree().create_timer(0.05), "timeout") + player_owner.gun_ray.force_raycast_update() + if player_owner.gun_ray.is_colliding(): + var hit = player_owner.gun_ray.get_collider() + if hit.has_method("damage"): + hit.rpc("damage", bullet_damage, "PIERCE", [player_owner.get_network_master(), player_owner.name], "using a pistol") + else: + var puff = preload("res://particles/DirtPuff.tscn").instance() + player_owner.world.add_child(puff) + puff.global_transform.origin = player_owner.gun_ray.get_collision_point() + puff.look_at(player_owner.gun_ray.get_collision_point() + player_owner.gun_ray.get_collision_normal(), Vector3.UP) + if hit.has_method("net_apply_impulse"): + hit.rpc("net_apply_impulse", -150*player_owner.melee_ray.global_transform.basis.z) + +func mouse_input(_m1: float, _m3: float, m2: float) -> void: + pass diff --git a/godot/scenes/weapons/pistol.tres b/godot/scenes/weapons/pistol.tres new file mode 100644 index 0000000..d7342d1 --- /dev/null +++ b/godot/scenes/weapons/pistol.tres @@ -0,0 +1,7 @@ +[gd_resource type="Resource" load_steps=2 format=2] + +[ext_resource path="res://scenes/weapons/pistol.gd" type="Script" id=1] + +[resource] +resource_local_to_scene = true +script = ExtResource( 1 ) diff --git a/godot/scenes/weapons/pistol.tscn b/godot/scenes/weapons/pistol.tscn new file mode 100644 index 0000000..6ea9408 --- /dev/null +++ b/godot/scenes/weapons/pistol.tscn @@ -0,0 +1,146 @@ +[gd_scene load_steps=23 format=2] + +[ext_resource path="res://meshes/pistol.tres" type="ArrayMesh" id=1] +[ext_resource path="res://animations/weapons/pistol_idle.tres" type="Animation" id=2] +[ext_resource path="res://animations/weapons/pistol_fire.tres" type="Animation" id=3] +[ext_resource path="res://meshes/pistol_skin.tres" type="Skin" id=4] +[ext_resource path="res://sounds/pistol.wav" type="AudioStream" id=5] +[ext_resource path="res://animations/weapons/pistol_reset.tres" type="Animation" id=6] +[ext_resource path="res://sounds/lock_click.wav" type="AudioStream" id=7] +[ext_resource path="res://sounds/reload_sounds.wav" type="AudioStream" id=8] + +[sub_resource type="Gradient" id=4] +offsets = PoolRealArray( 0, 0.577778 ) +colors = PoolColorArray( 1, 0.633789, 0.0625, 1, 0, 0, 0, 1 ) + +[sub_resource type="GradientTexture" id=5] +gradient = SubResource( 4 ) + +[sub_resource type="Curve" id=6] +max_value = 0.05 +_data = [ Vector2( 0, 0.05 ), 0.0, 0.0, 0, 0, Vector2( 1, 0 ), 0.0, 0.0, 0, 0 ] + +[sub_resource type="CurveTexture" id=7] +curve = SubResource( 6 ) + +[sub_resource type="ParticlesMaterial" id=1] +direction = Vector3( 0, 0.5, 1 ) +spread = 25.06 +initial_velocity = 3.0 +initial_velocity_random = 0.04 +angle = 360.0 +angle_random = 1.0 +scale_random = 0.03 +scale_curve = SubResource( 7 ) +color = Color( 1, 0.678431, 0, 1 ) +color_ramp = SubResource( 5 ) + +[sub_resource type="SpatialMaterial" id=2] +flags_unshaded = true +vertex_color_use_as_albedo = true +params_billboard_mode = 3 +particles_anim_h_frames = 1 +particles_anim_v_frames = 1 +particles_anim_loop = false + +[sub_resource type="QuadMesh" id=3] +material = SubResource( 2 ) +size = Vector2( 0.25, 1 ) + +[sub_resource type="Gradient" id=13] +offsets = PoolRealArray( 0, 0.16, 0.488889 ) +colors = PoolColorArray( 1, 0, 0, 1, 1, 0.679688, 0, 1, 0, 0, 0, 1 ) + +[sub_resource type="GradientTexture" id=14] +gradient = SubResource( 13 ) + +[sub_resource type="Curve" id=11] +_data = [ Vector2( 0, 0.405045 ), 0.0, 0.0, 0, 0, Vector2( 0.0806452, 1 ), 0.0, 0.0, 0, 0, Vector2( 0.229839, 0 ), 0.0, 0.0, 0, 0 ] + +[sub_resource type="CurveTexture" id=12] +curve = SubResource( 11 ) + +[sub_resource type="ParticlesMaterial" id=8] +spread = 14.56 +gravity = Vector3( 0, 0, 0 ) +initial_velocity = 14.7 +damping = 8.82 +angle = 360.0 +angle_random = 1.0 +scale_random = 0.07 +scale_curve = SubResource( 12 ) +color_ramp = SubResource( 14 ) +hue_variation = 0.07 + +[sub_resource type="SpatialMaterial" id=9] +flags_unshaded = true +vertex_color_use_as_albedo = true +params_billboard_mode = 3 +particles_anim_h_frames = 1 +particles_anim_v_frames = 1 +particles_anim_loop = false + +[sub_resource type="PrismMesh" id=10] +material = SubResource( 9 ) +size = Vector3( 0.3, 0.3, 0.3 ) + +[node name="pistol_model" type="Spatial"] + +[node name="AnimationPlayer" type="AnimationPlayer" parent="."] +autoplay = "idle" +anims/fire = ExtResource( 3 ) +anims/idle = ExtResource( 2 ) +anims/reset = ExtResource( 6 ) + +[node name="Skeleton" type="Skeleton" parent="."] +bones/0/name = "Hammer" +bones/0/parent = -1 +bones/0/rest = Transform( 0.942829, 0.333276, 9.68673e-08, -0.333276, 0.942829, 1.32945e-07, -4.7022e-08, -1.57628e-07, 1, 0.0808807, 0.0417358, 0.0358447 ) +bones/0/enabled = true +bones/0/bound_children = [ ] +bones/1/name = "Frizzen" +bones/1/parent = -1 +bones/1/rest = Transform( 0.877352, 0.479847, 1.229e-07, -0.479847, 0.877352, -1.26661e-07, -1.68604e-07, 5.21531e-08, 1, 0.16979, 0.0569473, 0.0387622 ) +bones/1/enabled = true +bones/1/bound_children = [ ] +bones/2/name = "neutral_bone" +bones/2/parent = -1 +bones/2/rest = Transform( 1, 0, 0, 0, 0, 1, 0, -1, 0, 0, 0, 0 ) +bones/2/enabled = true +bones/2/bound_children = [ ] + +[node name="Pistol" type="MeshInstance" parent="Skeleton"] +mesh = ExtResource( 1 ) +skin = ExtResource( 4 ) + +[node name="FireAudio" type="AudioStreamPlayer3D" parent="."] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.625837, 0, 0 ) +stream = ExtResource( 5 ) +attenuation_model = 2 + +[node name="LockParticles" type="Particles" parent="."] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.14647, 0.0421569, 0 ) +emitting = false +amount = 10 +lifetime = 0.5 +one_shot = true +explosiveness = 0.97 +process_material = SubResource( 1 ) +draw_pass_1 = SubResource( 3 ) + +[node name="MuzzleParticles" type="Particles" parent="."] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.529256, 0.065655, 0 ) +emitting = false +amount = 16 +lifetime = 0.67 +one_shot = true +explosiveness = 1.0 +process_material = SubResource( 8 ) +draw_pass_1 = SubResource( 10 ) + +[node name="ReloadAudio" type="AudioStreamPlayer3D" parent="."] +stream = ExtResource( 7 ) +unit_db = -6.154 + +[node name="PistolReload" type="AudioStreamPlayer" parent="."] +stream = ExtResource( 8 ) diff --git a/godot/scenes/weapons/rockets.gd b/godot/scenes/weapons/rockets.gd index c519fd6..5270186 100644 --- a/godot/scenes/weapons/rockets.gd +++ b/godot/scenes/weapons/rockets.gd @@ -1,37 +1,47 @@ -extends Node +extends Resource -var weapon_name = "ROCKETS" -var player -onready var world = get_tree().get_root().get_node("GAMEWORLD") +var player_owner: RigidBody = null +var can_throw: bool = true +var rockets_scene: Spatial = null -var ammo_full : int = 50 -var ammo : int +var rockets_left: int = 5 -var reload_time :float= 1.0 -var cooldown_time : float = 0.0 +const name: String = "HANDS" -func _ready(): - ammo = ammo_full - player = get_parent() +var trfrm = Transform ( Vector3(1.501,-0.142,-2.418), Vector3(-2.367,-0.693,-1.429),Vector3(-0.516,2.761,-0.483),Vector3(-0.206,0.639,-0.045)) -func _process(delta): - if cooldown_time > 0.0: - cooldown_time -= delta +func _init(): + rockets_scene = preload("res://scenes/weapons/rockets.tscn").instance() + rockets_scene.set_visible(false) + +func init(owner): + player_owner = owner + player_owner.add_weapon_vm(rockets_scene, trfrm) + +func select() -> void: + player_owner.rpc("anim_event", {"VMANIMPLAY" : "rockets_idle_vm"}) + if rockets_left > 0: rockets_scene.set_visible(true) + +func deselect() -> bool: + if !can_throw and rockets_left > 0: + return false + rockets_scene.set_visible(false) + return true func attack1(): - if cooldown_time <= 0.0 and ammo >= 1: - ammo -= 1 - cooldown_time = reload_time - rpc("add_rocket_to_scene", player.head.global_transform.basis, get_tree().get_network_unique_id()) - -remotesync func add_rocket_to_scene(dir, id): - var rocket = preload("res://scenes/ballistics/Rocket.tscn").instance() - world.get_node("BALLISTICS").add_child(rocket, true) - rocket.shooter = player.name + " (" + world.players_info[player.get_network_master()][0] + ")" - rocket.shooter_id = id - rocket.global_transform.origin = player.head.global_transform.origin - rocket.global_transform.basis = Basis(-1*dir.z, dir.y, dir.x) - rocket.add_collision_exception_with(player) - -func attack2(): + if !can_throw: + return + can_throw = false + player_owner.rpc("anim_event", {"VMANIMPLAY" : "rockets_launch_vm"}) + rockets_scene.get_node("AnimationPlayer").play("throw_animation") + yield(player_owner.get_tree().create_timer(1.43), "timeout") + rockets_left -= 1 + player_owner.rpc("add_rocket_to_scene", rockets_scene.global_transform.origin, player_owner.head.global_transform.basis, player_owner.get_network_master()) + yield(player_owner.get_tree().create_timer(1.6), "timeout") + if rockets_left > 0: + can_throw = true + else: + rockets_scene.set_visible(false) + +func mouse_input(_m1: float, _m3: float, m2: float) -> void: pass diff --git a/godot/scenes/weapons/w_Rockets.tscn b/godot/scenes/weapons/rockets.tres index c52f8e3..c94083f 100644 --- a/godot/scenes/weapons/w_Rockets.tscn +++ b/godot/scenes/weapons/rockets.tres @@ -1,6 +1,7 @@ -[gd_scene load_steps=2 format=2] +[gd_resource type="Resource" load_steps=2 format=2] [ext_resource path="res://scenes/weapons/rockets.gd" type="Script" id=1] -[node name="w_Rockets" type="Spatial"] +[resource] +resource_local_to_scene = true script = ExtResource( 1 ) diff --git a/godot/scenes/weapons/rockets.tscn b/godot/scenes/weapons/rockets.tscn new file mode 100644 index 0000000..b2c47d7 --- /dev/null +++ b/godot/scenes/weapons/rockets.tscn @@ -0,0 +1,71 @@ +[gd_scene load_steps=6 format=2] + +[ext_resource path="res://meshes/rocket.tres" type="ArrayMesh" id=1] + +[sub_resource type="ParticlesMaterial" id=1] +direction = Vector3( -1, 0, 0 ) +spread = 17.73 +initial_velocity = 3.0 +initial_velocity_random = 0.12 +angle = 360.0 +angle_random = 1.0 +scale = 0.02 +color = Color( 1, 0.701961, 0, 1 ) + +[sub_resource type="SpatialMaterial" id=2] +flags_unshaded = true +vertex_color_use_as_albedo = true +params_billboard_mode = 3 +particles_anim_h_frames = 1 +particles_anim_v_frames = 1 +particles_anim_loop = false + +[sub_resource type="QuadMesh" id=3] +material = SubResource( 2 ) +size = Vector2( 0.25, 1 ) + +[sub_resource type="Animation" id=4] +resource_name = "throw_animation" +length = 3.0 +tracks/0/type = "value" +tracks/0/path = NodePath("Sparks:emitting") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/keys = { +"times": PoolRealArray( 0, 0.5, 2.53138 ), +"transitions": PoolRealArray( 1, 1, 1 ), +"update": 1, +"values": [ false, true, false ] +} +tracks/1/type = "value" +tracks/1/path = NodePath(".:visible") +tracks/1/interp = 1 +tracks/1/loop_wrap = true +tracks/1/imported = false +tracks/1/enabled = true +tracks/1/keys = { +"times": PoolRealArray( 0, 1.4349, 2.55169 ), +"transitions": PoolRealArray( 1, 1, 1 ), +"update": 1, +"values": [ true, false, true ] +} + +[node name="rockets" type="Spatial"] + +[node name="rocket_mesh" type="MeshInstance" parent="."] +transform = Transform( -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 0, 0, 1, 0, 0, 0 ) +mesh = ExtResource( 1 ) + +[node name="Sparks" type="Particles" parent="."] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.217459, 0, 0 ) +emitting = false +amount = 16 +lifetime = 0.25 +local_coords = false +process_material = SubResource( 1 ) +draw_pass_1 = SubResource( 3 ) + +[node name="AnimationPlayer" type="AnimationPlayer" parent="."] +anims/throw_animation = SubResource( 4 ) |
