crouching, walking and jumping
This commit is contained in:
parent
58ccdbce0e
commit
f312e0a4a6
9 changed files with 71 additions and 60 deletions
|
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=24 format=3 uid="uid://cqrh2cc7m2i7f"]
|
||||
[gd_scene load_steps=21 format=3 uid="uid://cqrh2cc7m2i7f"]
|
||||
|
||||
[ext_resource type="Environment" uid="uid://d0cfgtx2yxw13" path="res://environments/prototype_environment.tres" id="1_i6jab"]
|
||||
[ext_resource type="Material" uid="uid://bx3f5vx71ynh5" path="res://materials/Graymat.tres" id="4_y6i55"]
|
||||
|
|
@ -17,20 +17,6 @@
|
|||
[ext_resource type="Script" path="res://scripts/multiplayer/spawn_system/team_spawner.gd" id="10_02ic3"]
|
||||
[ext_resource type="Script" uid="uid://3i00rp8urth7" path="res://scripts/object_container.gd" id="11_02ic3"]
|
||||
|
||||
[sub_resource type="Animation" id="Animation_y6i55"]
|
||||
length = 0.001
|
||||
|
||||
[sub_resource type="Animation" id="Animation_pi0y7"]
|
||||
resource_name = "main"
|
||||
length = 5.0
|
||||
loop_mode = 2
|
||||
|
||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_bno23"]
|
||||
_data = {
|
||||
&"RESET": SubResource("Animation_y6i55"),
|
||||
&"main": SubResource("Animation_pi0y7")
|
||||
}
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_ysk2e"]
|
||||
size = Vector3(15.324341, 0.96273804, 21.381592)
|
||||
|
||||
|
|
@ -233,12 +219,6 @@ operation = 2
|
|||
size = Vector3(20.339264, 4.566284, 3.4625244)
|
||||
material = ExtResource("7_8bje3")
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
||||
libraries = {
|
||||
&"": SubResource("AnimationLibrary_bno23")
|
||||
}
|
||||
autoplay = "main"
|
||||
|
||||
[node name="PlayersContainer" type="Node3D" parent="." node_paths=PackedStringArray("exlusion_list")]
|
||||
script = ExtResource("11_02ic3")
|
||||
exlusion_list = [NodePath("DefenceSpawn"), NodePath("AttackSpawn"), NodePath("SpectatorSpawn"), NodePath("MultiplayerSpawner")]
|
||||
|
|
|
|||
|
|
@ -166,3 +166,7 @@ menu_settings={
|
|||
3d_physics/layer_5="Players Attack Team"
|
||||
3d_physics/layer_6="Players Defence Team"
|
||||
3d_physics/layer_7="Interactible"
|
||||
|
||||
[physics]
|
||||
|
||||
3d/default_gravity=39.2
|
||||
|
|
|
|||
|
|
@ -8769,7 +8769,7 @@ script = ExtResource("8_f1ej7")
|
|||
current_state = NodePath("Stand")
|
||||
metadata/_custom_type_script = "uid://3777rkbebgjm"
|
||||
|
||||
[node name="Crouch" type="Node" parent="BodyStateMachine" node_paths=PackedStringArray("stand_up_area", "player", "player_movement", "animation_player", "weapon_system")]
|
||||
[node name="Crouch" type="Node" parent="BodyStateMachine" node_paths=PackedStringArray("stand_up_area", "player", "player_movement", "player_input", "animation_player", "weapon_system")]
|
||||
script = ExtResource("9_oprun")
|
||||
max_speed = 3.0
|
||||
acceleration = 50.0
|
||||
|
|
@ -8777,36 +8777,38 @@ deceleration = 50.0
|
|||
stand_up_area = NodePath("../../StandArea")
|
||||
player = NodePath("../..")
|
||||
player_movement = NodePath("../../PlayerMovement")
|
||||
player_input = NodePath("../../PlayerInput")
|
||||
animation_player = NodePath("../../AnimationPlayer")
|
||||
weapon_system = NodePath("../../WeaponSystem")
|
||||
|
||||
[node name="Stand" type="Node" parent="BodyStateMachine" node_paths=PackedStringArray("player", "player_movement", "weapon_system", "audio")]
|
||||
[node name="Stand" type="Node" parent="BodyStateMachine" node_paths=PackedStringArray("player", "player_movement", "player_input", "weapon_system", "audio")]
|
||||
script = ExtResource("10_a8ls1")
|
||||
max_speed = 6.0
|
||||
acceleration = 100.0
|
||||
deceleration = 50.0
|
||||
JUMP_VELOCITY = 6.0
|
||||
player = NodePath("../..")
|
||||
player_movement = NodePath("../../PlayerMovement")
|
||||
player_input = NodePath("../../PlayerInput")
|
||||
weapon_system = NodePath("../../WeaponSystem")
|
||||
audio = NodePath("../../StepAudio")
|
||||
step_delay = 0.25
|
||||
step_speed_curve = SubResource("Curve_fbysy")
|
||||
|
||||
[node name="Walk" type="Node" parent="BodyStateMachine" node_paths=PackedStringArray("player", "player_movement", "weapon_system")]
|
||||
[node name="Walk" type="Node" parent="BodyStateMachine" node_paths=PackedStringArray("player", "player_movement", "player_input", "weapon_system")]
|
||||
script = ExtResource("11_qfm1y")
|
||||
max_speed = 3.0
|
||||
acceleration = 50.0
|
||||
deceleration = 50.0
|
||||
player = NodePath("../..")
|
||||
player_movement = NodePath("../../PlayerMovement")
|
||||
player_input = NodePath("../../PlayerInput")
|
||||
weapon_system = NodePath("../../WeaponSystem")
|
||||
|
||||
[node name="Fall" type="Node" parent="BodyStateMachine" node_paths=PackedStringArray("player", "player_movement", "weapon_system", "land_sound")]
|
||||
script = ExtResource("12_fulsm")
|
||||
acceleration = 25.0
|
||||
player = NodePath("../..")
|
||||
player_movement = NodePath("../../PlayerMovement")
|
||||
acceleration = 25.0
|
||||
weapon_system = NodePath("../../WeaponSystem")
|
||||
land_sound = NodePath("../../LandAudio")
|
||||
|
||||
|
|
@ -8818,6 +8820,7 @@ animation_player = NodePath("../../AnimationPlayer")
|
|||
script = ExtResource("19_70eug")
|
||||
player = NodePath("..")
|
||||
player_input = NodePath("../PlayerInput")
|
||||
jump_velocity = 12.0
|
||||
|
||||
[node name="WeaponSystem" type="Node" parent="." node_paths=PackedStringArray("animation_player", "camera", "player")]
|
||||
script = ExtResource("4_qlg0r")
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ var crouching: bool = false
|
|||
var scoping: bool = false
|
||||
var walking: bool = false
|
||||
|
||||
signal jumped
|
||||
signal drop
|
||||
signal switch_weapon(to_slot: StringName)
|
||||
signal fire_begin
|
||||
|
|
@ -70,7 +71,7 @@ func _input(event: InputEvent) -> void:
|
|||
crouch_on_server.rpc_id(1,false)
|
||||
if event.is_action_released("plr_crouch") and not ClientSettings.TOGGLE_CROUCH and crouching:
|
||||
crouching = false
|
||||
crouch_on_server.rpc_id(1,false)
|
||||
crouch_on_server.rpc_id(1,true)
|
||||
|
||||
if event.is_action_pressed("plr_walk"):
|
||||
if ClientSettings.TOGGLE_WALK:
|
||||
|
|
@ -81,7 +82,7 @@ func _input(event: InputEvent) -> void:
|
|||
walk_on_server.rpc_id(1,false)
|
||||
if event.is_action_released("plr_walk") and not ClientSettings.TOGGLE_WALK and walking:
|
||||
walking = false
|
||||
walk_on_server.rpc_id(1,false)
|
||||
walk_on_server.rpc_id(1,true)
|
||||
|
||||
if event.is_action_pressed("plr_scope"):
|
||||
if ClientSettings.TOGGLE_SCOPE:
|
||||
|
|
@ -92,7 +93,7 @@ func _input(event: InputEvent) -> void:
|
|||
scope_on_server.rpc_id(1,false)
|
||||
if event.is_action_released("plr_scope") and not ClientSettings.TOGGLE_SCOPE and scoping:
|
||||
scoping = false
|
||||
scope_on_server.rpc_id(1,false)
|
||||
scope_on_server.rpc_id(1,true)
|
||||
|
||||
if event.is_action_pressed("plr_reload"):
|
||||
reload_on_server.rpc_id(1)
|
||||
|
|
@ -101,6 +102,9 @@ func _input(event: InputEvent) -> void:
|
|||
interact_on_server.rpc_id(1,false)
|
||||
if event.is_action_released("plr_interact"):
|
||||
interact_on_server.rpc_id(1,true)
|
||||
|
||||
if event.is_action_pressed("plr_jump"):
|
||||
jump_on_server.rpc_id(1)
|
||||
|
||||
@rpc("authority","call_local","reliable")
|
||||
func switch_on_server(slot: StringName) -> void:
|
||||
|
|
@ -166,3 +170,8 @@ func interact_on_server(end: bool) -> void:
|
|||
interact_end.emit()
|
||||
else:
|
||||
interact_begin.emit()
|
||||
|
||||
@rpc("authority","call_local","reliable")
|
||||
func jump_on_server() -> void:
|
||||
if not multiplayer.is_server(): return
|
||||
jumped.emit()
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ class_name PlayerMovement
|
|||
|
||||
@export var player: Player
|
||||
@export var player_input: PlayerInput
|
||||
|
||||
@export var jump_velocity: float
|
||||
var disabled: bool
|
||||
|
||||
func disable() -> void:
|
||||
|
|
@ -24,3 +26,6 @@ func process_movement(max_speed: float,acceleration: float,deceleration: float,d
|
|||
else:
|
||||
player.velocity.x = move_toward(player.velocity.x, 0, deceleration*delta)
|
||||
player.velocity.z = move_toward(player.velocity.z, 0, deceleration*delta)
|
||||
|
||||
func jump() -> void:
|
||||
player.velocity.y = jump_velocity
|
||||
|
|
|
|||
|
|
@ -8,22 +8,22 @@ extends State
|
|||
@export var stand_up_area: Area3D
|
||||
@export var player: Player
|
||||
@export var player_movement: PlayerMovement
|
||||
@export var player_input: PlayerInput
|
||||
@export var animation_player: AnimationPlayer
|
||||
@export var crouch_time: float = 0.1
|
||||
@export var weapon_system: WeaponSystem
|
||||
|
||||
func enter() -> void:
|
||||
animation_player.play("crouch",-1,1/crouch_time)
|
||||
player_input.crouch_end.connect(try_end_crouch)
|
||||
|
||||
func exit() -> void:
|
||||
animation_player.play("crouch",-1,-1/crouch_time,true)
|
||||
player_input.crouch_end.disconnect(try_end_crouch)
|
||||
|
||||
func physics_update(delta: float) -> void:
|
||||
if not is_multiplayer_authority():
|
||||
return
|
||||
if Input.is_action_just_pressed("plr_jump") and player.is_on_floor() and toggle:
|
||||
transition.emit("Stand")
|
||||
return
|
||||
|
||||
if not player.is_on_floor():
|
||||
transition.emit("Fall")
|
||||
|
|
@ -31,7 +31,6 @@ func physics_update(delta: float) -> void:
|
|||
|
||||
player_movement.process_movement(max_speed * weapon_system.get_speed_modifier(),acceleration,deceleration,delta)
|
||||
|
||||
func state_input(event: InputEvent) -> void:
|
||||
if (toggle == true and event.is_action_pressed("plr_crouch")) or (toggle == false and event.is_action_released("plr_crouch")):
|
||||
if stand_up_area.has_overlapping_bodies() == false:
|
||||
transition.emit("Stand")
|
||||
func try_end_crouch() -> void:
|
||||
if player.is_on_floor() and stand_up_area.has_overlapping_bodies() == false:
|
||||
transition.emit("Stand")
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@ extends State
|
|||
@export var max_speed: float = 5.0
|
||||
@export var acceleration: float = 2.0
|
||||
@export var deceleration: float = 200.0
|
||||
@export var JUMP_VELOCITY: float = 4.5
|
||||
@export var player: Player
|
||||
@export var player_movement: PlayerMovement
|
||||
@export var player_input: PlayerInput
|
||||
@export var weapon_system: WeaponSystem
|
||||
@export var audio: MultiplayerAudio3D
|
||||
@export var step_delay: float
|
||||
|
|
@ -14,18 +14,19 @@ extends State
|
|||
var step_time: float
|
||||
|
||||
func enter() -> void:
|
||||
pass
|
||||
player_input.jumped.connect(on_jumped)
|
||||
player_input.crouch_begin.connect(begin_crouch)
|
||||
player_input.walk_begin.connect(begin_walk)
|
||||
|
||||
func exit() -> void:
|
||||
player_input.jumped.disconnect(on_jumped)
|
||||
player_input.crouch_begin.disconnect(begin_crouch)
|
||||
player_input.walk_begin.disconnect(begin_walk)
|
||||
step_time = 0
|
||||
|
||||
func physics_update(delta: float) -> void:
|
||||
if not is_multiplayer_authority():
|
||||
return
|
||||
if Input.is_action_just_pressed("plr_jump") and player.is_on_floor():
|
||||
player.velocity.y = JUMP_VELOCITY * sign(weapon_system.get_speed_modifier())
|
||||
transition.emit("Fall")
|
||||
return
|
||||
|
||||
if not player.is_on_floor():
|
||||
transition.emit("Fall")
|
||||
|
|
@ -38,9 +39,13 @@ func physics_update(delta: float) -> void:
|
|||
|
||||
player_movement.process_movement(max_speed * weapon_system.get_speed_modifier(),acceleration,deceleration,delta)
|
||||
|
||||
func state_input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("plr_crouch"):
|
||||
transition.emit("Crouch")
|
||||
|
||||
if event.is_action_pressed("plr_walk"):
|
||||
transition.emit("Walk")
|
||||
func on_jumped() -> void:
|
||||
if player.is_on_floor():
|
||||
player_movement.jump()
|
||||
transition.emit("Fall")
|
||||
|
||||
func begin_walk() -> void:
|
||||
transition.emit("Walk")
|
||||
|
||||
func begin_crouch() -> void:
|
||||
transition.emit("Crouch")
|
||||
|
|
|
|||
|
|
@ -6,21 +6,22 @@ extends State
|
|||
@export var JUMP_VELOCITY: float = 4.5
|
||||
@export var player: Player
|
||||
@export var player_movement: PlayerMovement
|
||||
@export var player_input: PlayerInput
|
||||
@export var weapon_system: WeaponSystem
|
||||
|
||||
func enter() -> void:
|
||||
pass
|
||||
player_input.crouch_begin.connect(begin_crouch)
|
||||
player_input.walk_end.connect(end_walk)
|
||||
player_input.jumped.connect(on_jumped)
|
||||
|
||||
func exit() -> void:
|
||||
pass
|
||||
player_input.crouch_begin.disconnect(begin_crouch)
|
||||
player_input.walk_end.disconnect(end_walk)
|
||||
player_input.jumped.disconnect(on_jumped)
|
||||
|
||||
func physics_update(delta: float) -> void:
|
||||
if not is_multiplayer_authority():
|
||||
return
|
||||
if Input.is_action_just_pressed("plr_jump") and player.is_on_floor():
|
||||
player.velocity.y = JUMP_VELOCITY
|
||||
transition.emit("Fall")
|
||||
return
|
||||
|
||||
if not player.is_on_floor():
|
||||
transition.emit("Fall")
|
||||
|
|
@ -28,9 +29,13 @@ func physics_update(delta: float) -> void:
|
|||
|
||||
player_movement.process_movement(max_speed * weapon_system.get_speed_modifier(),acceleration,deceleration,delta)
|
||||
|
||||
func state_input(event: InputEvent) -> void:
|
||||
if event.is_action_released("plr_walk"):
|
||||
transition.emit("Stand")
|
||||
|
||||
if event.is_action_pressed("plr_crouch"):
|
||||
transition.emit("Crouch")
|
||||
func on_jumped() -> void:
|
||||
if player.is_on_floor():
|
||||
player_movement.jump()
|
||||
transition.emit("Fall")
|
||||
|
||||
func end_walk() -> void:
|
||||
transition.emit("Stand")
|
||||
|
||||
func begin_crouch() -> void:
|
||||
transition.emit("Crouch")
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ func _ready() -> void:
|
|||
|
||||
else:
|
||||
push_warning("Child of state machine is not state")
|
||||
current_state.enter()
|
||||
|
||||
func on_transition_required(to: StringName):
|
||||
if is_multiplayer_authority() == false:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue