summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMalfurious <m@lfurio.us>2022-09-12 03:37:12 -0400
committerMalfurious <m@lfurio.us>2022-09-12 03:37:12 -0400
commit31bc7653eb89688b9890523e1f2b39cc867837fc (patch)
treee5f25d2bfcf1205732707c0d89335f5d35d9904c
parente9baf6602be3efbf5ea566b4e0c80a12c38f475e (diff)
parent355dcc29148461dd79815e76fa1a5a887a44ecc3 (diff)
downloadproject-s-31bc7653eb89688b9890523e1f2b39cc867837fc.tar.gz
project-s-31bc7653eb89688b9890523e1f2b39cc867837fc.zip
Merge branch 'dynamic-viewmodel'
* dynamic-viewmodel: ViewModel cycles characters on interact/ping Decouple ViewModel and the BaseCharacter Allow dynamic character material
-rw-r--r--assets/characters/base_character/BaseCharacter.gd7
-rw-r--r--assets/maps/misc/dev_plane/DevPlane.tscn17
-rw-r--r--assets/maps/misc/test_map/shipping_yard_map.tscn17
-rw-r--r--assets/view_model/ViewModel.gd15
-rw-r--r--assets/view_model/ViewModel.tscn5
-rw-r--r--assets/weapons/goo_gun/Bullet.gd6
-rw-r--r--assets/weapons/goo_gun/GooGun.gd2
7 files changed, 56 insertions, 13 deletions
diff --git a/assets/characters/base_character/BaseCharacter.gd b/assets/characters/base_character/BaseCharacter.gd
index bcc0f26..5d1b013 100644
--- a/assets/characters/base_character/BaseCharacter.gd
+++ b/assets/characters/base_character/BaseCharacter.gd
@@ -1,10 +1,17 @@
extends KinematicBody
+export var material : Material = null
export var is_firing = false
export var look_angle = 0
export var weapon_pitch = 0
export var weapon_pitch_bias = deg2rad(20)
+func _ready():
+ look_angle = rotation.y
+ if material != null:
+ $Body.set("material/0", material)
+ $GooGun.projectile_material = material
+
func _process(_delta):
var effective_weapon_pitch = weapon_pitch - weapon_pitch_bias if is_firing else weapon_pitch
effective_weapon_pitch = clamp(effective_weapon_pitch, deg2rad(-90), deg2rad(90))
diff --git a/assets/maps/misc/dev_plane/DevPlane.tscn b/assets/maps/misc/dev_plane/DevPlane.tscn
index a17a112..5134d2e 100644
--- a/assets/maps/misc/dev_plane/DevPlane.tscn
+++ b/assets/maps/misc/dev_plane/DevPlane.tscn
@@ -1,7 +1,9 @@
-[gd_scene load_steps=9 format=2]
+[gd_scene load_steps=11 format=2]
[ext_resource path="res://assets/maps/misc/dev_plane/tile_color.png" type="Texture" id=1]
[ext_resource path="res://assets/view_model/ViewModel.tscn" type="PackedScene" id=2]
+[ext_resource path="res://assets/characters/base_character/BaseCharacter.tscn" type="PackedScene" id=3]
+[ext_resource path="res://assets/characters/base_character/enemy_material.tres" type="Material" id=4]
[sub_resource type="SpatialMaterial" id=6]
albedo_texture = ExtResource( 1 )
@@ -25,14 +27,21 @@ material = SubResource( 3 )
[node name="DevPlane" type="Spatial"]
+[node name="ViewModel" parent="." instance=ExtResource( 2 )]
+character = NodePath("../FriendlyPlayer")
+
+[node name="FriendlyPlayer" parent="." groups=["players"] instance=ExtResource( 3 )]
+transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.75, 12 )
+
+[node name="EnemyPlayer" parent="." groups=["players"] instance=ExtResource( 3 )]
+transform = Transform( -1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 0.75, -12 )
+material = ExtResource( 4 )
+
[node name="DirectionalLight" type="DirectionalLight" parent="."]
transform = Transform( -4.37114e-08, -0.292372, 0.956305, 0, 0.956305, 0.292372, -1, 1.278e-08, -4.18014e-08, 0, 10, 0 )
shadow_enabled = true
directional_shadow_blend_splits = true
-[node name="ViewModel" parent="." instance=ExtResource( 2 )]
-transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.8, 12 )
-
[node name="Geometry" type="Spatial" parent="."]
[node name="Floor" type="StaticBody" parent="Geometry"]
diff --git a/assets/maps/misc/test_map/shipping_yard_map.tscn b/assets/maps/misc/test_map/shipping_yard_map.tscn
index f2c5efb..f5cf4eb 100644
--- a/assets/maps/misc/test_map/shipping_yard_map.tscn
+++ b/assets/maps/misc/test_map/shipping_yard_map.tscn
@@ -1,4 +1,4 @@
-[gd_scene load_steps=63 format=2]
+[gd_scene load_steps=65 format=2]
[ext_resource path="res://assets/maps/misc/test_map/test_map_assets/shipping_containers/red_malfurious_container/red_malfurious_container.tscn" type="PackedScene" id=1]
[ext_resource path="res://assets/maps/misc/test_map/test_map_assets/platforms/supports/support_01.tscn" type="PackedScene" id=2]
@@ -36,6 +36,8 @@
[ext_resource path="res://custom_shaders/liquid.gdshader" type="Shader" id=34]
[ext_resource path="res://assets/maps/misc/test_map/test_map_assets/environment/buildings/building_1/building_1.tscn" type="PackedScene" id=35]
[ext_resource path="res://assets/maps/misc/test_map/test_map_assets/decals/ftf_graffiti.tscn" type="PackedScene" id=36]
+[ext_resource path="res://assets/characters/base_character/BaseCharacter.tscn" type="PackedScene" id=37]
+[ext_resource path="res://assets/characters/base_character/enemy_material.tres" type="Material" id=38]
[sub_resource type="ArrayMesh" id=1]
resource_name = "crane_load_Cylinder002"
@@ -313,6 +315,16 @@ polygon_points = PoolVector2Array( 1.17958, -3.9844, 1.18686, 1.20034, -1.04211,
[node name="shipping_yard_map" type="Spatial"]
+[node name="ViewModel" parent="." instance=ExtResource( 11 )]
+character = NodePath("../FriendlyPlayer")
+
+[node name="FriendlyPlayer" parent="." groups=["players"] instance=ExtResource( 37 )]
+transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2.066, 105.317 )
+
+[node name="EnemyPlayer" parent="." groups=["players"] instance=ExtResource( 37 )]
+transform = Transform( -1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 2.066, -105.317 )
+material = ExtResource( 38 )
+
[node name="left_side" type="Spatial" parent="."]
[node name="shipping_yard_main_terrain" parent="left_side" instance=ExtResource( 6 )]
@@ -1318,9 +1330,6 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.859604, 0, 34.7394 )
[node name="ftf_graffiti" parent="decorative/non_symmetrical_graffiti" instance=ExtResource( 36 )]
transform = Transform( -4.37114e-08, -1, 4.37114e-08, 0.05007, -4.58452e-08, -0.998746, 0.998746, -4.14679e-08, 0.05007, 20.2422, 2.83189, 37.9582 )
-[node name="ViewModel" parent="." instance=ExtResource( 11 )]
-transform = Transform( 1, 0, 1.74846e-07, 0, 1, 0, -1.74846e-07, 0, 1, 0, 2.06622, 105.317 )
-
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = ExtResource( 21 )
diff --git a/assets/view_model/ViewModel.gd b/assets/view_model/ViewModel.gd
index cb85117..6d42a5a 100644
--- a/assets/view_model/ViewModel.gd
+++ b/assets/view_model/ViewModel.gd
@@ -8,7 +8,7 @@ export var gravity = 35
var velocity = Vector3.ZERO
var snap = Vector3.DOWN
-onready var character = $BaseCharacter
+export(NodePath) onready var character = get_node(character)
onready var anchor = $Anchor
onready var spring_arm = $Anchor/SpringArm
onready var fps_label = $fps_label
@@ -64,6 +64,9 @@ func _physics_process(delta):
# Handle extra player inputs
character.is_firing = Input.is_action_pressed("fire")
+
+ if Input.is_action_just_pressed("ping"):
+ cycle_parent()
func _unhandled_input(event):
# Implement mouse aim direction
@@ -73,3 +76,13 @@ func _unhandled_input(event):
spring_arm.rotation_degrees.y -= event.relative.x * aim_sensitivity
spring_arm.rotation_degrees.y = wrapf(spring_arm.rotation_degrees.y, 0, 360)
+
+func cycle_parent():
+ var parents = get_tree().get_nodes_in_group("players")
+ var idx = parents.find(character)
+
+ if idx < 0 or idx == parents.size() - 1:
+ if parents.size() > 0:
+ character = parents[0]
+ else:
+ character = parents[idx + 1]
diff --git a/assets/view_model/ViewModel.tscn b/assets/view_model/ViewModel.tscn
index 3412e91..f6390af 100644
--- a/assets/view_model/ViewModel.tscn
+++ b/assets/view_model/ViewModel.tscn
@@ -1,13 +1,10 @@
-[gd_scene load_steps=3 format=2]
+[gd_scene load_steps=2 format=2]
-[ext_resource path="res://assets/characters/base_character/BaseCharacter.tscn" type="PackedScene" id=1]
[ext_resource path="res://assets/view_model/ViewModel.gd" type="Script" id=2]
[node name="ViewModel" type="Spatial"]
script = ExtResource( 2 )
-[node name="BaseCharacter" parent="." instance=ExtResource( 1 )]
-
[node name="Anchor" type="Spatial" parent="."]
[node name="SpringArm" type="SpringArm" parent="Anchor"]
diff --git a/assets/weapons/goo_gun/Bullet.gd b/assets/weapons/goo_gun/Bullet.gd
index 1a4c01a..2edba6b 100644
--- a/assets/weapons/goo_gun/Bullet.gd
+++ b/assets/weapons/goo_gun/Bullet.gd
@@ -1,4 +1,10 @@
extends RigidBody
+export var material : Material = null
+
+func _ready():
+ if material != null:
+ $MeshInstance.set("material/0", material)
+
func _on_Bullet_body_entered(_body):
queue_free()
diff --git a/assets/weapons/goo_gun/GooGun.gd b/assets/weapons/goo_gun/GooGun.gd
index 6a6758d..6cb87fc 100644
--- a/assets/weapons/goo_gun/GooGun.gd
+++ b/assets/weapons/goo_gun/GooGun.gd
@@ -2,6 +2,7 @@ extends Spatial
export var is_firing = false
export var fire_rate = 0.075
+export var projectile_material : Material = null
export var projectile_spread = 0 #TODO
export var projectile_scalar = 40
export var look_angle = 0
@@ -22,6 +23,7 @@ func _physics_process(delta):
func do_fire_projectile():
var bullet = Bullet.instance()
+ bullet.material = projectile_material
$Nozzle.add_child(bullet)
bullet.set_as_toplevel(true)
var shoot_direction = Vector3.FORWARD.rotated(Vector3.LEFT, weapon_pitch)