movement system rework
This commit is contained in:
parent
900502ec8a
commit
792465a33c
7 changed files with 47 additions and 31 deletions
|
|
@ -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")]
|
[node name="Crouch" type="Node" parent="BodyStateMachine" node_paths=PackedStringArray("stand_up_area", "player", "animation_player", "weapon_system")]
|
||||||
script = ExtResource("9_oprun")
|
script = ExtResource("9_oprun")
|
||||||
|
acceleration = 50.0
|
||||||
|
deceleration = 50.0
|
||||||
stand_up_area = NodePath("../../StandArea")
|
stand_up_area = NodePath("../../StandArea")
|
||||||
player = NodePath("../..")
|
player = NodePath("../..")
|
||||||
animation_player = NodePath("../../AnimationPlayer")
|
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")]
|
[node name="Stand" type="Node" parent="BodyStateMachine" node_paths=PackedStringArray("player", "weapon_system")]
|
||||||
script = ExtResource("10_a8ls1")
|
script = ExtResource("10_a8ls1")
|
||||||
|
acceleration = 100.0
|
||||||
|
deceleration = 50.0
|
||||||
JUMP_VELOCITY = 6.0
|
JUMP_VELOCITY = 6.0
|
||||||
player = NodePath("../..")
|
player = NodePath("../..")
|
||||||
weapon_system = NodePath("../../WeaponSystem")
|
weapon_system = NodePath("../../WeaponSystem")
|
||||||
|
|
||||||
[node name="Walk" type="Node" parent="BodyStateMachine" node_paths=PackedStringArray("player", "weapon_system")]
|
[node name="Walk" type="Node" parent="BodyStateMachine" node_paths=PackedStringArray("player", "weapon_system")]
|
||||||
script = ExtResource("11_qfm1y")
|
script = ExtResource("11_qfm1y")
|
||||||
|
acceleration = 50.0
|
||||||
|
deceleration = 50.0
|
||||||
player = NodePath("../..")
|
player = NodePath("../..")
|
||||||
weapon_system = NodePath("../../WeaponSystem")
|
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")
|
script = ExtResource("12_fulsm")
|
||||||
player = NodePath("../..")
|
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")]
|
[node name="WeaponSystem" type="Node" parent="." node_paths=PackedStringArray("animation_player", "camera", "player")]
|
||||||
script = ExtResource("4_qlg0r")
|
script = ExtResource("4_qlg0r")
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ func request_spawn(data: Variant) -> Node:
|
||||||
if data.has("scene") == false:
|
if data.has("scene") == false:
|
||||||
return Node.new()
|
return Node.new()
|
||||||
var node = load(data.scene).instantiate()
|
var node = load(data.scene).instantiate()
|
||||||
if data.has(["impulse"]):
|
if data.has("impulse"):
|
||||||
if data.has_all(["ammo","remaining_ammo","slot"]):
|
if data.has_all(["ammo","remaining_ammo","slot"]):
|
||||||
node.weapon.ammo = data.ammo
|
node.weapon.ammo = data.ammo
|
||||||
node.weapon.remaining_ammo = data.remaining_ammo
|
node.weapon.remaining_ammo = data.remaining_ammo
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,9 @@
|
||||||
extends State
|
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 toggle: bool = false
|
||||||
@export var stand_up_area: Area3D
|
@export var stand_up_area: Area3D
|
||||||
@export var player: Player
|
@export var player: Player
|
||||||
|
|
@ -14,7 +17,7 @@ func enter() -> void:
|
||||||
func exit() -> void:
|
func exit() -> void:
|
||||||
animation_player.play("crouch",-1,-1/crouch_time,true)
|
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():
|
if not is_multiplayer_authority():
|
||||||
return
|
return
|
||||||
if Input.is_action_just_pressed("plr_jump") and player.is_on_floor() and toggle:
|
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 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 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:
|
if direction:
|
||||||
player.velocity.x = direction.x * 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 = direction.z * modified_speed
|
player.velocity.z = clamp(player.velocity.z + direction.z * acceleration * delta,-modified_max_speed*abs(direction.z),modified_max_speed*abs(direction.z))
|
||||||
else:
|
else:
|
||||||
player.velocity.x = move_toward(player.velocity.x, 0, modified_speed)
|
player.velocity.x = move_toward(player.velocity.x, 0, deceleration*delta)
|
||||||
player.velocity.z = move_toward(player.velocity.z, 0, modified_speed)
|
player.velocity.z = move_toward(player.velocity.z, 0, deceleration*delta)
|
||||||
|
|
||||||
func state_input(event: InputEvent) -> void:
|
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 (toggle == true and event.is_action_pressed("plr_crouch")) or (toggle == false and event.is_action_released("plr_crouch")):
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
extends State
|
extends State
|
||||||
|
|
||||||
@export var player: Player
|
@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:
|
func enter() -> void:
|
||||||
pass
|
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 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 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:
|
if direction:
|
||||||
player.velocity.x = direction.x * SPEED
|
if abs(player.velocity.x + direction.x * acceleration * delta) < abs(modified_max_speed * direction.x):
|
||||||
player.velocity.z = direction.z * SPEED
|
player.velocity.x += direction.x * acceleration * delta
|
||||||
else:
|
if abs(player.velocity.y + direction.y * acceleration * delta) < abs(modified_max_speed * direction.y):
|
||||||
player.velocity.x = move_toward(player.velocity.x, 0, SPEED)
|
player.velocity.z += direction.z * acceleration * delta
|
||||||
player.velocity.z = move_toward(player.velocity.z, 0, SPEED)
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
extends State
|
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 JUMP_VELOCITY: float = 4.5
|
||||||
@export var player: Player
|
@export var player: Player
|
||||||
@export var weapon_system: WeaponSystem
|
@export var weapon_system: WeaponSystem
|
||||||
|
|
@ -11,7 +13,7 @@ func enter() -> void:
|
||||||
func exit() -> void:
|
func exit() -> void:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
func physics_update(_delta: float) -> void:
|
func physics_update(delta: float) -> void:
|
||||||
if not is_multiplayer_authority():
|
if not is_multiplayer_authority():
|
||||||
return
|
return
|
||||||
if Input.is_action_just_pressed("plr_jump") and player.is_on_floor():
|
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 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 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:
|
if direction:
|
||||||
player.velocity.x = direction.x * 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 = direction.z * modified_speed
|
player.velocity.z = clamp(player.velocity.z + direction.z * acceleration * delta,-modified_max_speed*abs(direction.z),modified_max_speed*abs(direction.z))
|
||||||
else:
|
else:
|
||||||
player.velocity.x = move_toward(player.velocity.x, 0, modified_speed)
|
player.velocity.x = move_toward(player.velocity.x, 0, deceleration*delta)
|
||||||
player.velocity.z = move_toward(player.velocity.z, 0, modified_speed)
|
player.velocity.z = move_toward(player.velocity.z, 0, deceleration*delta)
|
||||||
|
|
||||||
func state_input(event: InputEvent) -> void:
|
func state_input(event: InputEvent) -> void:
|
||||||
if event.is_action_pressed("plr_crouch"):
|
if event.is_action_pressed("plr_crouch"):
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
extends State
|
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 JUMP_VELOCITY: float = 4.5
|
||||||
@export var player: Player
|
@export var player: Player
|
||||||
@export var weapon_system: WeaponSystem
|
@export var weapon_system: WeaponSystem
|
||||||
|
|
@ -11,7 +13,7 @@ func enter() -> void:
|
||||||
func exit() -> void:
|
func exit() -> void:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
func physics_update(_delta: float) -> void:
|
func physics_update(delta: float) -> void:
|
||||||
if not is_multiplayer_authority():
|
if not is_multiplayer_authority():
|
||||||
return
|
return
|
||||||
if Input.is_action_just_pressed("plr_jump") and player.is_on_floor():
|
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 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 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:
|
if direction:
|
||||||
player.velocity.x = direction.x * 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 = direction.z * modified_speed
|
player.velocity.z = clamp(player.velocity.z + direction.z * acceleration * delta,-modified_max_speed*abs(direction.z),modified_max_speed*abs(direction.z))
|
||||||
else:
|
else:
|
||||||
player.velocity.x = move_toward(player.velocity.x, 0, modified_speed)
|
player.velocity.x = move_toward(player.velocity.x, 0, deceleration*delta)
|
||||||
player.velocity.z = move_toward(player.velocity.z, 0, modified_speed)
|
player.velocity.z = move_toward(player.velocity.z, 0, deceleration*delta)
|
||||||
|
|
||||||
func state_input(event: InputEvent) -> void:
|
func state_input(event: InputEvent) -> void:
|
||||||
if event.is_action_released("plr_walk"):
|
if event.is_action_released("plr_walk"):
|
||||||
|
|
|
||||||
|
|
@ -98,7 +98,7 @@ func drop():
|
||||||
drop_data.remaining_ammo = current_state.remaining_ammo
|
drop_data.remaining_ammo = current_state.remaining_ammo
|
||||||
drop_data.slot = current_state.slot
|
drop_data.slot = current_state.slot
|
||||||
drop_data.position = camera.global_position
|
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)
|
Session.spawn(drop_data)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue