forked from unfa/liblast
Implemented simple jetpack
parent
6fb574b31a
commit
54e9d9cf44
|
@ -1,6 +1,6 @@
|
|||
extends CharacterBody3D
|
||||
|
||||
@export var mouse_sensitivity := 0.35
|
||||
@export var mouse_sensitivity := 0.15
|
||||
|
||||
@onready var main = get_tree().root.get_node("Main")
|
||||
@onready var hud = main.get_node("HUD")
|
||||
|
@ -70,14 +70,22 @@ var speed_type := {
|
|||
"water": 5
|
||||
}
|
||||
var gravity := 28
|
||||
var jump := 14
|
||||
var jump := 14 * 1
|
||||
|
||||
var jetpack_active = false
|
||||
|
||||
var jetpack_thrust = 48 # force applied against gravity
|
||||
var jetpack_tank = 0.5 # maximum fuel (jetpack use time
|
||||
var jetpack_fuel = jetpack_tank # current fuel (use time) left
|
||||
var jetpack_recharge = 0.25 # how long to recharge to full
|
||||
|
||||
var velocity := Vector3.ZERO
|
||||
var gravity_vec := Vector3.ZERO
|
||||
|
||||
@rpc func update_movement(player_transform, head_rotation):
|
||||
@rpc(nosync,ordered) func update_movement(player_transform, head_rotation, jetpack):
|
||||
global_transform = player_transform
|
||||
head.set_rotation(head_rotation)
|
||||
jetpack_active = jetpack
|
||||
|
||||
func _ready() -> void:
|
||||
#Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||
|
@ -144,6 +152,8 @@ func _process(delta):
|
|||
view_zoom = min(view_zoom_target, view_zoom + delta * 4)
|
||||
elif not view_zoom_direction and view_zoom > view_zoom_target:
|
||||
view_zoom = max(view_zoom_target, view_zoom - delta * 4)
|
||||
|
||||
$Jetpack/GPUParticles3D.emitting = jetpack_active
|
||||
|
||||
func damage(hp: int):
|
||||
var target = main.player_list.players[self.get_network_authority()]
|
||||
|
@ -180,7 +190,7 @@ func _physics_process(delta):
|
|||
|
||||
direction = Vector3.ZERO
|
||||
|
||||
if is_on_floor() and ground_check.is_colliding():
|
||||
if is_on_floor() and ground_check.is_colliding() and not jetpack_active:
|
||||
snap = -get_floor_normal()
|
||||
medium = "ground"
|
||||
gravity_vec = Vector3.ZERO
|
||||
|
@ -202,7 +212,18 @@ func _physics_process(delta):
|
|||
direction -= transform.basis.x
|
||||
if Input.is_action_pressed("move_right"):
|
||||
direction += transform.basis.x
|
||||
|
||||
jetpack_active = Input.is_action_pressed("move_special") if jetpack_fuel > 0 else false
|
||||
|
||||
|
||||
if jetpack_active:
|
||||
gravity_vec[1] += jetpack_thrust * delta
|
||||
jetpack_fuel -= delta
|
||||
elif jetpack_fuel < jetpack_tank:
|
||||
jetpack_fuel = min(jetpack_tank, jetpack_fuel + jetpack_recharge * delta)
|
||||
|
||||
#print("Jetpack fuel: ", jetpack_fuel, " active: ", jetpack_active, " delta: ", delta, " gravity vec: ", gravity_vec)
|
||||
|
||||
if direction.length() > 0: # normalized() will return a null
|
||||
direction = direction.normalized()
|
||||
|
||||
|
@ -230,7 +251,7 @@ func _physics_process(delta):
|
|||
# else:
|
||||
# rpc_id(1, &'update_movement', global_transform, head.get_rotation())
|
||||
#
|
||||
rpc(&'update_movement', global_transform, head.get_rotation())
|
||||
rpc(&'update_movement', global_transform, head.get_rotation(), jetpack_active)
|
||||
|
||||
# (stair) climbing
|
||||
# ↓ disabled - Tween is undergoing redesign in Godot 4
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
[gd_scene load_steps=7 format=3 uid="uid://cwuys43c7ak61"]
|
||||
[gd_scene load_steps=17 format=3 uid="uid://cwuys43c7ak61"]
|
||||
|
||||
[ext_resource type="Script" path="res://Assets/Characters/Player.gd" id="1"]
|
||||
[ext_resource type="PackedScene" path="res://Assets/Weapons/Weapon.tscn" id="3"]
|
||||
[ext_resource type="Texture2D" uid="uid://cguy76rs8e220" path="res://Assets/Effects/Flame.png" id="3_jw7jd"]
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="4"]
|
||||
albedo_color = Color(0.545098, 0.545098, 0.545098, 1)
|
||||
|
@ -24,6 +25,54 @@ height = 1.7
|
|||
radius = 0.25
|
||||
height = 0.5
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_y4s21"]
|
||||
albedo_color = Color(0.243137, 0.243137, 0.243137, 1)
|
||||
metallic = 1.0
|
||||
roughness = 0.45
|
||||
|
||||
[sub_resource type="CylinderMesh" id="CylinderMesh_8yana"]
|
||||
top_radius = 0.1
|
||||
bottom_radius = 0.1
|
||||
height = 0.8
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_mytx0"]
|
||||
blend_mode = 1
|
||||
shading_mode = 0
|
||||
vertex_color_use_as_albedo = true
|
||||
albedo_color = Color(3, 3, 3, 1)
|
||||
albedo_texture = ExtResource( "3_jw7jd" )
|
||||
albedo_tex_force_srgb = true
|
||||
billboard_mode = 3
|
||||
particles_anim_h_frames = 2
|
||||
particles_anim_v_frames = 2
|
||||
particles_anim_loop = false
|
||||
|
||||
[sub_resource type="QuadMesh" id="QuadMesh_355ks"]
|
||||
material = SubResource( "StandardMaterial3D_mytx0" )
|
||||
|
||||
[sub_resource type="Curve" id="Curve_elwjc"]
|
||||
_data = [Vector2(0, 1), 0.0, 0.0, 0, 0, Vector2(1, 0), 0.0, 0.0, 0, 0]
|
||||
|
||||
[sub_resource type="Gradient" id="Gradient_fu53v"]
|
||||
offsets = PackedFloat32Array(0, 0.0888031, 0.227799, 0.393822, 1)
|
||||
colors = PackedColorArray(0, 0, 0, 1, 0.671875, 0.946167, 1, 1, 0.996185, 1, 0.511719, 1, 1, 0.732788, 0.222656, 1, 0, 0, 0, 1)
|
||||
|
||||
[sub_resource type="GradientTexture" id="GradientTexture_nta0d"]
|
||||
gradient = SubResource( "Gradient_fu53v" )
|
||||
width = 128
|
||||
|
||||
[sub_resource type="CurveTexture" id="CurveTexture_cvegn"]
|
||||
width = 512
|
||||
texture_mode = 1
|
||||
curve = SubResource( "Curve_elwjc" )
|
||||
|
||||
[sub_resource type="ParticlesMaterial" id="ParticlesMaterial_px65a"]
|
||||
scale_curve = SubResource( "CurveTexture_cvegn" )
|
||||
color_ramp = SubResource( "GradientTexture_nta0d" )
|
||||
anim_offset_min = -100.0
|
||||
anim_offset_max = 100.0
|
||||
collision_friction = 1.0
|
||||
|
||||
[node name="Player" type="CharacterBody3D"]
|
||||
script = ExtResource( "1" )
|
||||
|
||||
|
@ -80,3 +129,34 @@ script = null
|
|||
[node name="Camera3D" type="Camera3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.00117874, 2.00811, 2.99957)
|
||||
script = null
|
||||
|
||||
[node name="Jetpack" type="MeshInstance3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.93832, 0.5022)
|
||||
material_override = SubResource( "StandardMaterial3D_y4s21" )
|
||||
mesh = SubResource( "CylinderMesh_8yana" )
|
||||
surface_material_override/0 = null
|
||||
script = null
|
||||
|
||||
[node name="GPUParticles3D" type="CPUParticles3D" parent="Jetpack"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.45039, 0.00259888)
|
||||
emitting = false
|
||||
amount = 128
|
||||
lifetime = 0.5
|
||||
fixed_fps = 30
|
||||
local_coords = false
|
||||
mesh = SubResource( "QuadMesh_355ks" )
|
||||
scale_amount_curve = SubResource( "Curve_elwjc" )
|
||||
color_ramp = SubResource( "Gradient_fu53v" )
|
||||
anim_offset_min = -100.0
|
||||
anim_offset_max = 100.0
|
||||
script = null
|
||||
|
||||
[node name="GPUParticles3D2" type="GPUParticles3D" parent="Jetpack"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.45039, 0.00259888)
|
||||
visible = false
|
||||
emitting = false
|
||||
lifetime = 3.0
|
||||
local_coords = false
|
||||
process_material = SubResource( "ParticlesMaterial_px65a" )
|
||||
draw_pass_1 = SubResource( "QuadMesh_355ks" )
|
||||
script = null
|
||||
|
|
Loading…
Reference in New Issue