diff --git a/scenes/molikman.tscn b/scenes/molikman.tscn index b36952a..c9ac8fc 100644 --- a/scenes/molikman.tscn +++ b/scenes/molikman.tscn @@ -270,6 +270,8 @@ metadata/_custom_type_script = "uid://3777rkbebgjm" [node name="Crouch" type="Node" parent="BodyStateMachine" node_paths=PackedStringArray("stand_up_area", "player", "animation_player", "weapon_system")] script = ExtResource("9_oprun") +acceleration = 50.0 +deceleration = 50.0 stand_up_area = NodePath("../../StandArea") player = NodePath("../..") animation_player = NodePath("../../AnimationPlayer") @@ -277,19 +279,24 @@ weapon_system = NodePath("../../WeaponSystem") [node name="Stand" type="Node" parent="BodyStateMachine" node_paths=PackedStringArray("player", "weapon_system")] script = ExtResource("10_a8ls1") +acceleration = 100.0 +deceleration = 50.0 JUMP_VELOCITY = 6.0 player = NodePath("../..") weapon_system = NodePath("../../WeaponSystem") [node name="Walk" type="Node" parent="BodyStateMachine" node_paths=PackedStringArray("player", "weapon_system")] script = ExtResource("11_qfm1y") +acceleration = 50.0 +deceleration = 50.0 player = NodePath("../..") weapon_system = NodePath("../../WeaponSystem") -[node name="Fall" type="Node" parent="BodyStateMachine" node_paths=PackedStringArray("player")] +[node name="Fall" type="Node" parent="BodyStateMachine" node_paths=PackedStringArray("player", "weapon_system")] script = ExtResource("12_fulsm") player = NodePath("../..") -SPEED = 5.0 +acceleration = 25.0 +weapon_system = NodePath("../../WeaponSystem") [node name="WeaponSystem" type="Node" parent="." node_paths=PackedStringArray("animation_player", "camera", "player")] script = ExtResource("4_qlg0r") diff --git a/scripts/multiplayer/spawn_system/dyn_objects_spawner.gd b/scripts/multiplayer/spawn_system/dyn_objects_spawner.gd index 7c641dd..01fd6e4 100644 --- a/scripts/multiplayer/spawn_system/dyn_objects_spawner.gd +++ b/scripts/multiplayer/spawn_system/dyn_objects_spawner.gd @@ -8,7 +8,7 @@ func request_spawn(data: Variant) -> Node: if data.has("scene") == false: return Node.new() var node = load(data.scene).instantiate() - if data.has(["impulse"]): + if data.has("impulse"): if data.has_all(["ammo","remaining_ammo","slot"]): node.weapon.ammo = data.ammo node.weapon.remaining_ammo = data.remaining_ammo diff --git a/scripts/player/states/crouching.gd b/scripts/player/states/crouching.gd index f4b782c..2ff7c33 100644 --- a/scripts/player/states/crouching.gd +++ b/scripts/player/states/crouching.gd @@ -1,6 +1,9 @@ extends State -@export var speed: float = 2.5 +@export var max_speed: float = 2.5 +@export var acceleration: float = 1.0 +@export var deceleration: float = 100.0 + @export var toggle: bool = false @export var stand_up_area: Area3D @export var player: Player @@ -14,7 +17,7 @@ func enter() -> void: func exit() -> void: animation_player.play("crouch",-1,-1/crouch_time,true) -func physics_update(_delta: float) -> void: +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: @@ -27,13 +30,13 @@ func physics_update(_delta: float) -> void: var input_dir := Input.get_vector("plr_strafe_r","plr_strafe_l", "plr_back","plr_forward") var direction := (player.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized() - var modified_speed = speed * weapon_system.get_speed_modifier() + var modified_max_speed = max_speed * weapon_system.get_speed_modifier() if direction: - player.velocity.x = direction.x * modified_speed - player.velocity.z = direction.z * modified_speed + player.velocity.x = clamp(player.velocity.x + direction.x * acceleration * delta,-modified_max_speed*abs(direction.x),modified_max_speed*abs(direction.x)) + player.velocity.z = clamp(player.velocity.z + direction.z * acceleration * delta,-modified_max_speed*abs(direction.z),modified_max_speed*abs(direction.z)) else: - player.velocity.x = move_toward(player.velocity.x, 0, modified_speed) - player.velocity.z = move_toward(player.velocity.z, 0, modified_speed) + player.velocity.x = move_toward(player.velocity.x, 0, deceleration*delta) + player.velocity.z = move_toward(player.velocity.z, 0, 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")): diff --git a/scripts/player/states/falling.gd b/scripts/player/states/falling.gd index fe53303..136d4e8 100644 --- a/scripts/player/states/falling.gd +++ b/scripts/player/states/falling.gd @@ -1,7 +1,9 @@ extends State @export var player: Player -@export var SPEED: float +@export var max_speed: float = 5.0 +@export var acceleration: float +@export var weapon_system: WeaponSystem func enter() -> void: pass @@ -20,9 +22,9 @@ func physics_update(delta: float) -> void: var input_dir := Input.get_vector("plr_strafe_r","plr_strafe_l", "plr_back","plr_forward") var direction := (player.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized() + var modified_max_speed = max_speed * weapon_system.get_speed_modifier() if direction: - player.velocity.x = direction.x * SPEED - player.velocity.z = direction.z * SPEED - else: - player.velocity.x = move_toward(player.velocity.x, 0, SPEED) - player.velocity.z = move_toward(player.velocity.z, 0, SPEED) + if abs(player.velocity.x + direction.x * acceleration * delta) < abs(modified_max_speed * direction.x): + player.velocity.x += direction.x * acceleration * delta + if abs(player.velocity.y + direction.y * acceleration * delta) < abs(modified_max_speed * direction.y): + player.velocity.z += direction.z * acceleration * delta diff --git a/scripts/player/states/standing.gd b/scripts/player/states/standing.gd index 645cac8..7190923 100644 --- a/scripts/player/states/standing.gd +++ b/scripts/player/states/standing.gd @@ -1,6 +1,8 @@ extends State -@export var speed: float = 5.0 +@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 weapon_system: WeaponSystem @@ -11,7 +13,7 @@ func enter() -> void: func exit() -> void: pass -func physics_update(_delta: float) -> void: +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(): @@ -25,13 +27,13 @@ func physics_update(_delta: float) -> void: var input_dir := Input.get_vector("plr_strafe_r","plr_strafe_l", "plr_back","plr_forward") var direction := (player.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized() - var modified_speed := speed * weapon_system.get_speed_modifier() + var modified_max_speed = max_speed * weapon_system.get_speed_modifier() if direction: - player.velocity.x = direction.x * modified_speed - player.velocity.z = direction.z * modified_speed + player.velocity.x = clamp(player.velocity.x + direction.x * acceleration * delta,-modified_max_speed*abs(direction.x),modified_max_speed*abs(direction.x)) + player.velocity.z = clamp(player.velocity.z + direction.z * acceleration * delta,-modified_max_speed*abs(direction.z),modified_max_speed*abs(direction.z)) else: - player.velocity.x = move_toward(player.velocity.x, 0, modified_speed) - player.velocity.z = move_toward(player.velocity.z, 0, modified_speed) + player.velocity.x = move_toward(player.velocity.x, 0, deceleration*delta) + player.velocity.z = move_toward(player.velocity.z, 0, deceleration*delta) func state_input(event: InputEvent) -> void: if event.is_action_pressed("plr_crouch"): diff --git a/scripts/player/states/walk.gd b/scripts/player/states/walk.gd index 7e1b901..9dc8f5b 100644 --- a/scripts/player/states/walk.gd +++ b/scripts/player/states/walk.gd @@ -1,6 +1,8 @@ extends State -@export var speed: float = 2.5 +@export var max_speed: float = 2.5 +@export var acceleration: float = 1.0 +@export var deceleration: float = 100.0 @export var JUMP_VELOCITY: float = 4.5 @export var player: Player @export var weapon_system: WeaponSystem @@ -11,7 +13,7 @@ func enter() -> void: func exit() -> void: pass -func physics_update(_delta: float) -> void: +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(): @@ -25,13 +27,13 @@ func physics_update(_delta: float) -> void: var input_dir := Input.get_vector("plr_strafe_r","plr_strafe_l", "plr_back","plr_forward") var direction := (player.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized() - var modified_speed = speed * weapon_system.get_speed_modifier() + var modified_max_speed = max_speed * weapon_system.get_speed_modifier() if direction: - player.velocity.x = direction.x * modified_speed - player.velocity.z = direction.z * modified_speed + player.velocity.x = clamp(player.velocity.x + direction.x * acceleration * delta,-modified_max_speed*abs(direction.x),modified_max_speed*abs(direction.x)) + player.velocity.z = clamp(player.velocity.z + direction.z * acceleration * delta,-modified_max_speed*abs(direction.z),modified_max_speed*abs(direction.z)) else: - player.velocity.x = move_toward(player.velocity.x, 0, modified_speed) - player.velocity.z = move_toward(player.velocity.z, 0, modified_speed) + player.velocity.x = move_toward(player.velocity.x, 0, deceleration*delta) + player.velocity.z = move_toward(player.velocity.z, 0, deceleration*delta) func state_input(event: InputEvent) -> void: if event.is_action_released("plr_walk"): diff --git a/scripts/weapon_system/weapon_system.gd b/scripts/weapon_system/weapon_system.gd index 6e57772..99a5912 100644 --- a/scripts/weapon_system/weapon_system.gd +++ b/scripts/weapon_system/weapon_system.gd @@ -98,7 +98,7 @@ func drop(): drop_data.remaining_ammo = current_state.remaining_ammo drop_data.slot = current_state.slot drop_data.position = camera.global_position - drop_data.impulse = -camera.global_basis.z * 10 + drop_data.impulse = -camera.global_basis.z * 10 + player.velocity Session.spawn(drop_data)