Recoil system
This commit is contained in:
parent
1c062489b1
commit
cdfce4c7db
11 changed files with 144 additions and 8 deletions
|
|
@ -64,7 +64,7 @@ func _physics_process(delta: float) -> void:
|
|||
|
||||
# Get the input direction and handle the movement/deceleration.
|
||||
# As good practice, you should replace UI actions with custom gameplay actions.
|
||||
var input_dir := Input.get_vector("plr_strafe_l", "plr_strafe_r", "plr_forward", "plr_back")
|
||||
var input_dir := Input.get_vector("plr_strafe_r","plr_strafe_l", "plr_back","plr_forward")
|
||||
var direction := (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
|
||||
if direction:
|
||||
velocity.x = direction.x * SPEED
|
||||
|
|
|
|||
|
|
@ -1,24 +1,59 @@
|
|||
extends Camera3D
|
||||
|
||||
const COLLINEAR = 1.5707963267948966
|
||||
class_name PlayerCamera
|
||||
|
||||
@export var SENSITIVITY = 0.02
|
||||
|
||||
|
||||
var vertical_compensation : float
|
||||
var compensation_tween: Tween
|
||||
var compensate: bool = false
|
||||
var compensation_speed: float
|
||||
@export var compensation_time: float = 1.0
|
||||
@export var compensation_delay: float = 0.5
|
||||
|
||||
func _enter_tree() -> void:
|
||||
set_multiplayer_authority(get_parent().name.to_int())
|
||||
|
||||
func _ready() -> void:
|
||||
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
||||
# Move to level controller when possible
|
||||
#Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
||||
if not is_multiplayer_authority():
|
||||
return
|
||||
current = true
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if compensate:
|
||||
if abs(vertical_compensation) <= 0.001:
|
||||
vertical_compensation = 0
|
||||
compensate = false
|
||||
return
|
||||
rotate_camera(0,compensation_speed * delta)
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if not is_multiplayer_authority():
|
||||
return
|
||||
if event is InputEventMouseMotion:
|
||||
get_parent().rotate_y(-event.relative.x * SENSITIVITY)
|
||||
rotate_x(-event.relative.y * SENSITIVITY)
|
||||
rotation.x = clamp(rotation.x,-COLLINEAR,COLLINEAR)
|
||||
orthonormalize()
|
||||
rotate_camera(-event.relative.x * SENSITIVITY,-event.relative.y * SENSITIVITY)
|
||||
|
||||
func rotate_camera(x,y) -> void:
|
||||
get_parent().rotate_y(x)
|
||||
rotation.x = clamp(rotation.x + y,-PI/2,PI/2)
|
||||
orthonormalize()
|
||||
if sign(vertical_compensation) == sign(y):
|
||||
vertical_compensation -= y
|
||||
|
||||
func recoil(x,y) -> void:
|
||||
rotate_camera(x,y)
|
||||
vertical_compensation -= y
|
||||
if compensation_tween:
|
||||
compensation_tween.kill()
|
||||
compensation_tween = create_tween()
|
||||
compensation_tween.tween_interval(compensation_delay)
|
||||
compensation_tween.tween_callback(start_compensating)
|
||||
|
||||
func start_compensating() -> void:
|
||||
compensate = true
|
||||
print(vertical_compensation)
|
||||
compensation_speed = vertical_compensation / compensation_time
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue