From c232b92e2dde1277324d1f89d0e75ae641e4ac3b Mon Sep 17 00:00:00 2001 From: Anson Bridges Date: Wed, 7 Sep 2022 14:07:30 -0400 Subject: reorganized, ladders, vehicle control --- godot/scenes/environment/CaptureFlag.gd | 84 +++++++++++++++++++++++ godot/scenes/environment/CaptureFlag.tscn | 93 +++++++++++++++++++++++++ godot/scenes/environment/Ladder.gd | 21 ++++++ godot/scenes/environment/Ladder.tscn | 48 +++++++++++++ godot/scenes/environment/Water.tscn | 109 ++++++++++++++++++++++++++++++ 5 files changed, 355 insertions(+) create mode 100644 godot/scenes/environment/CaptureFlag.gd create mode 100644 godot/scenes/environment/CaptureFlag.tscn create mode 100644 godot/scenes/environment/Ladder.gd create mode 100644 godot/scenes/environment/Ladder.tscn create mode 100644 godot/scenes/environment/Water.tscn (limited to 'godot/scenes/environment') diff --git a/godot/scenes/environment/CaptureFlag.gd b/godot/scenes/environment/CaptureFlag.gd new file mode 100644 index 0000000..81a9fc5 --- /dev/null +++ b/godot/scenes/environment/CaptureFlag.gd @@ -0,0 +1,84 @@ +extends Spatial + +onready var flag = $flag_mesh +const flag_high : float = 5.4 +const flag_low : float = 1.0 +var capture_speed : float = 1 + +var state = "IDLE_HIGH" #IDLE_HIGH, IDLE_LOW, CAPTURING, HOISTING. capturing cannot be blocked, hoisting can + +var teams_in_zone = [] +var foreign_in_zone = false +var team = "NONE" + +# Called when the node enters the scene tree for the first time. +func _ready(): + $flag_mesh/Label.text = team + +remotesync func update_text(text): + $flag_mesh/Label.text = text + +remote func update_position(height): + flag.transform.origin.y = height + +remotesync func capture(): + $flag_mesh/capture_audio.play() + +func _physics_process(delta): + if is_network_master(): + teams_in_zone = [] + foreign_in_zone = false + for body in $CaptureArea.get_overlapping_bodies(): + if body.is_in_group("player") and !(body.team in teams_in_zone): + if body.team != team: + foreign_in_zone = true + teams_in_zone.append(body.team) + if state == "IDLE_HIGH" and foreign_in_zone: + state = "CAPTURING" + if state == "CAPTURING" and !foreign_in_zone: + state = "IDLE_HIGH" + if state == "IDLE_LOW" and team in teams_in_zone: + state = "HOISTING" + if state == "HOISTING" and !(team in teams_in_zone): + state = "IDLE_LOW" + + if state == "CAPTURING": + if flag.transform.origin.y > flag_low: + flag.transform.origin.y -= delta * capture_speed + rpc("update_position",flag.transform.origin.y) + else: + flag.transform.origin.y = flag_low + state = "IDLE_LOW" + team = "NONE" + rpc("update_text",team) + if state == "IDLE_HIGH": + if flag.transform.origin.y <= flag_high: + flag.transform.origin.y += delta * capture_speed + rpc("update_position",flag.transform.origin.y) + if state == "IDLE_LOW": + if flag.transform.origin.y > flag_low: + flag.transform.origin.y -= delta * capture_speed + rpc("update_position",flag.transform.origin.y) + else: + team = "NONE" + rpc("update_text",team) + flag.transform.origin.y = flag_low + if team == "NONE" and len(teams_in_zone) == 1: + team = teams_in_zone[0] + rpc("update_text",team) + state = "HOISTING" + if state == "HOISTING": + if len(teams_in_zone) == 1: + flag.transform.origin.y += delta * capture_speed + rpc("update_position",flag.transform.origin.y) + if flag.transform.origin.y >= flag_high: + rpc("capture") + state = "IDLE_HIGH" + +func mp_init(init_info): + flag.transform.origin.y = init_info["height"] + team = init_info["team"] + $flag_mesh/Label.text = team + +func get_init_info(): #info necessary to replicate item + return {"height" : flag.transform.origin.y, "team" : team } diff --git a/godot/scenes/environment/CaptureFlag.tscn b/godot/scenes/environment/CaptureFlag.tscn new file mode 100644 index 0000000..1347f64 --- /dev/null +++ b/godot/scenes/environment/CaptureFlag.tscn @@ -0,0 +1,93 @@ +[gd_scene load_steps=17 format=2] + +[ext_resource path="res://textures/conc_slabs01_c.png" type="Texture" id=1] +[ext_resource path="res://theming/FreeMono.otf" type="DynamicFontData" id=2] +[ext_resource path="res://scenes/environment/CaptureFlag.gd" type="Script" id=3] +[ext_resource path="res://sounds/capture.wav" type="AudioStream" id=4] + +[sub_resource type="CylinderShape" id=8] +height = 6.0 +radius = 0.05 + +[sub_resource type="ConvexPolygonShape" id=9] +points = PoolVector3Array( -1, -0.25, -1, -1, 0.25, -1, 1, -0.25, -1, -1, -0.25, 1, -1, 0.25, 1, 1, 0.25, -1, 1, -0.25, 1, 1, 0.25, 1 ) + +[sub_resource type="SpatialMaterial" id=1] +albedo_texture = ExtResource( 1 ) + +[sub_resource type="CubeMesh" id=2] +material = SubResource( 1 ) +size = Vector3( 2, 0.5, 2 ) + +[sub_resource type="OpenSimplexNoise" id=4] + +[sub_resource type="NoiseTexture" id=5] +width = 64 +height = 64 +seamless = true +noise = SubResource( 4 ) + +[sub_resource type="SpatialMaterial" id=6] +albedo_texture = SubResource( 5 ) + +[sub_resource type="CylinderMesh" id=7] +material = SubResource( 6 ) +top_radius = 0.05 +bottom_radius = 0.05 +height = 6.0 + +[sub_resource type="BoxShape" id=3] +extents = Vector3( 2, 2.24192, 2 ) + +[sub_resource type="SpatialMaterial" id=10] +params_cull_mode = 2 + +[sub_resource type="QuadMesh" id=11] +material = SubResource( 10 ) + +[sub_resource type="DynamicFont" id=12] +size = 32 +outline_size = 3 +font_data = ExtResource( 2 ) + +[node name="CaptureFlag" type="Spatial"] +script = ExtResource( 3 ) + +[node name="Collider" type="StaticBody" parent="."] + +[node name="CollisionShape" type="CollisionShape" parent="Collider"] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 3, 0 ) +shape = SubResource( 8 ) + +[node name="CollisionShape2" type="CollisionShape" parent="Collider"] +shape = SubResource( 9 ) + +[node name="base_mesh" type="MeshInstance" parent="."] +mesh = SubResource( 2 ) + +[node name="pole_mesh" type="MeshInstance" parent="."] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2.97816, 0 ) +mesh = SubResource( 7 ) + +[node name="CaptureArea" type="Area" parent="."] +collision_layer = 32768 +collision_mask = 32768 + +[node name="CollisionShape" type="CollisionShape" parent="CaptureArea"] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.46129, 0 ) +shape = SubResource( 3 ) + +[node name="flag_mesh" type="MeshInstance" parent="."] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.512, 5.4, 0 ) +mesh = SubResource( 11 ) + +[node name="Label" type="Label3D" parent="flag_mesh"] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.653017, 0 ) +billboard = 1 +font = SubResource( 12 ) + +[node name="capture_audio" type="AudioStreamPlayer3D" parent="flag_mesh"] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.512, -0.014648, 0 ) +stream = ExtResource( 4 ) +attenuation_model = 3 +max_distance = 200.0 diff --git a/godot/scenes/environment/Ladder.gd b/godot/scenes/environment/Ladder.gd new file mode 100644 index 0000000..af31c3f --- /dev/null +++ b/godot/scenes/environment/Ladder.gd @@ -0,0 +1,21 @@ +extends Spatial + +onready var top = $Top +onready var bottom = $Bottom + +func _ready(): + if !OS.is_debug_build(): + $DebugVisMesh.visible = false + +#point at which a player should enter the ladder given their current location +func get_nearest_point_to_route(point_global: Vector3) -> Vector3: + var t : Vector3 = top.global_transform.origin + var b : Vector3 = bottom.global_transform.origin + return b + clamp(get_climb_scalar(point_global), 0.0, 1.0)*(t-b) + +#ladder climb "progress" +func get_climb_scalar(point_global: Vector3) -> float: + var t : Vector3 = top.global_transform.origin + var b : Vector3 = bottom.global_transform.origin + #(T−B)⋅(P-B) / (T−B)⋅(T−B) + return (t-b).dot(point_global-b) / (t-b).dot(t-b) diff --git a/godot/scenes/environment/Ladder.tscn b/godot/scenes/environment/Ladder.tscn new file mode 100644 index 0000000..ee99c68 --- /dev/null +++ b/godot/scenes/environment/Ladder.tscn @@ -0,0 +1,48 @@ +[gd_scene load_steps=7 format=2] + +[ext_resource path="res://scenes/environment/Ladder.gd" type="Script" id=1] + +[sub_resource type="ConvexPolygonShape" id=2] +points = PoolVector3Array( 0.5, 0.5, 0.075, 0.5, 0.5, -0.075, -0.5, 0.5, 0.075, 0.5, -0.5, 0.075, 0.5, -0.5, -0.075, -0.5, 0.5, -0.075, -0.5, -0.5, 0.075, -0.5, -0.5, -0.075 ) + +[sub_resource type="CubeMesh" id=1] +size = Vector3( 1, 1, 0.15 ) + +[sub_resource type="SpatialMaterial" id=4] +albedo_color = Color( 0.764706, 0.764706, 0.764706, 1 ) + +[sub_resource type="CubeMesh" id=5] +material = SubResource( 4 ) +size = Vector3( 0.9, 1, 0.15 ) + +[sub_resource type="GDScript" id=3] +resource_name = "adjust_ladder_top" +script/source = "extends Spatial + +#top of ladder path is above actual top so that player can easily dismount +func _ready(): + transform.origin.y += 0.2 / get_parent().scale.y +" + +[node name="Ladder" type="Spatial"] +script = ExtResource( 1 ) + +[node name="LadderArea" type="Area" parent="."] + +[node name="CollisionShape" type="CollisionShape" parent="LadderArea"] +shape = SubResource( 2 ) + +[node name="DebugVisMesh" type="MeshInstance" parent="."] +mesh = SubResource( 1 ) + +[node name="DebugVisMesh2" type="MeshInstance" parent="DebugVisMesh"] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.0222434 ) +mesh = SubResource( 5 ) +skeleton = NodePath("../..") + +[node name="Bottom" type="Spatial" parent="."] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.5, 0.5 ) + +[node name="Top" type="Spatial" parent="."] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0.5 ) +script = SubResource( 3 ) diff --git a/godot/scenes/environment/Water.tscn b/godot/scenes/environment/Water.tscn new file mode 100644 index 0000000..04410b1 --- /dev/null +++ b/godot/scenes/environment/Water.tscn @@ -0,0 +1,109 @@ +[gd_scene load_steps=7 format=2] + +[ext_resource path="res://textures/WaterC.jpg" type="Texture" id=1] +[ext_resource path="res://textures/WaterA.jpg" type="Texture" id=2] + +[sub_resource type="QuadMesh" id=1] +size = Vector2( 2, 2 ) + +[sub_resource type="Shader" id=2] +code = "shader_type spatial; +render_mode world_vertex_coords, cull_disabled; + +uniform int ShaderID = 4; + +uniform vec4 Color : hint_color; +uniform vec4 BackgroundColor : hint_color; +uniform sampler2D Texture : hint_albedo; +uniform sampler2D BackgroundTexture : hint_albedo; +varying vec3 TriplanarPosistion; +varying vec3 PowerNormal; +uniform vec3 UVScale = vec3(1); +uniform vec3 UVOffset; +uniform float Transparent = 1.0; +uniform float Power = 0.0; +uniform vec4 EmissionColor : hint_color; + +void vertex() +{ + vec2 Pos = vec2(0); + Pos.x += TIME * 0.05; + TANGENT = vec3(0.0, 0.0, -1.0) * abs(NORMAL.x); + TANGENT += vec3(1.0, 0.0, 0.0) * abs(NORMAL.y); + TANGENT += vec3(1.0, 0.0, 0.0) * abs(NORMAL.z); + TANGENT = normalize(TANGENT); + BINORMAL = vec3(0.0, -1.0, 0.0) * abs(NORMAL.x); + BINORMAL += vec3(0.0, 0.0, 1.0) * abs(NORMAL.y); + BINORMAL += vec3(0.0, -1.0, 0.0) * abs(NORMAL.z); + BINORMAL = normalize(BINORMAL); + PowerNormal = pow(abs(NORMAL), vec3(1.0)); + PowerNormal /= dot(PowerNormal, vec3(1.0)); + TriplanarPosistion = VERTEX * UVScale + UVOffset;// + vec3(Pos.x, Pos.y, 0); + TriplanarPosistion *= vec3(1.0, -1.0, 1.0); +} + + +vec4 TriplanarTexture(sampler2D TSampler,vec3 TWeights,vec3 TTriplanarPosition) +{ + vec4 Sampler = vec4(0.0); + Sampler += texture(TSampler, TTriplanarPosition.xy) * TWeights.z; + Sampler += texture(TSampler, TTriplanarPosition.xz) * TWeights.y; + Sampler += texture(TSampler, TTriplanarPosition.zy * vec2(-1.0, 1.0)) * TWeights.x; + return Sampler; +} + + + +void fragment() +{ + vec3 NewOffset = vec3(0); + NewOffset.x = cos(TIME + TriplanarPosistion.x * 2.0) * 0.05; + NewOffset.z = cos(TIME + TriplanarPosistion.z) * 0.05; + + ALBEDO = TriplanarTexture(BackgroundTexture, PowerNormal, TriplanarPosistion + NewOffset).rgb * BackgroundColor.rgb; + ALBEDO += TriplanarTexture(Texture, PowerNormal, TriplanarPosistion + NewOffset * 5.1).rgb * Color.rgb; + EMISSION = ALBEDO * Power; + + float depth = texture(DEPTH_TEXTURE, SCREEN_UV).r; + depth = depth*2.0 - 1.0; + depth = PROJECTION_MATRIX[3][2] / (depth + PROJECTION_MATRIX[2][2]); + depth = depth + VERTEX.z; + depth = exp(-depth*0.05); + //depth *= 0.01; + ALPHA = clamp(1.0-depth, Transparent, 1.0); +} + + + + +" + +[sub_resource type="ShaderMaterial" id=3] +render_priority = -100 +shader = SubResource( 2 ) +shader_param/ShaderID = 4 +shader_param/Color = Color( 0.270588, 0.372549, 0.423529, 0.490196 ) +shader_param/BackgroundColor = Color( 0.560784, 0.560784, 0.560784, 1 ) +shader_param/UVScale = Vector3( 0.05, 0.05, 0.05 ) +shader_param/UVOffset = null +shader_param/Transparent = 0.4 +shader_param/Power = 0.2 +shader_param/EmissionColor = null +shader_param/Texture = ExtResource( 2 ) +shader_param/BackgroundTexture = ExtResource( 1 ) + +[sub_resource type="BoxShape" id=4] + +[node name="Water" type="Spatial"] + +[node name="MeshInstance" type="MeshInstance" parent="."] +transform = Transform( 1, 0, 0, 0, 0, 1, 0, -1, 0, 0, 0, 0 ) +mesh = SubResource( 1 ) +material/0 = SubResource( 3 ) + +[node name="WaterArea" type="Area" parent="."] +collision_layer = 4 + +[node name="CollisionShape" type="CollisionShape" parent="WaterArea"] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1, 0 ) +shape = SubResource( 4 ) -- cgit v1.2.3