Zoom the view with "z" key - it's not possible to shoot while zoomed in (to avoid sniping with all weapons).

remotes/1699310152913738325/tmp_refs/heads/legacy
unfa 2021-04-21 23:22:00 +02:00
parent d2a1c7e121
commit 40079d2b0a
3 changed files with 28 additions and 3 deletions

View File

@ -1,6 +1,9 @@
class_name Player
extends KinematicBody
const FOV_NORMAL = 70
const FOV_ZOOM = 25
const GRAVITY = Vector3.DOWN * 9.8 * 1.5
const UP = Vector3.UP
const JUMP_VELOCITY = 8
@ -203,7 +206,8 @@ remote func mouselook_abs(x, y):
rotation.y = y
remote func mouselook(rel):
var sensitivity = MOUSE_SENSITIVITY * game.mouse_sensitivity_multiplier
var sensitivity = MOUSE_SENSITIVITY * game.mouse_sensitivity_multiplier * (camera.fov / FOV_NORMAL)
print("Sensitivity: ", sensitivity)
rotate_y(- rel.x * sensitivity)
camera.rotation.x = clamp(camera.rotation.x-rel.y * sensitivity, -PI/2, PI/2)
@ -359,6 +363,8 @@ sync func unset_death():
is_dead = false
for i in $Camera/Hand/Weapons.get_children():
i.reset()
$HUD/Crosshair.modulate = Color(1,1,1,1)
camera.fov = FOV_NORMAL
func shoot():
# The underscore indicates an unused variable.
@ -403,7 +409,7 @@ func _unhandled_input(event):
rpc("set_jetpack_active", false)
# Weapon
if event.is_action_pressed("WeaponPrimary"):
if event.is_action_pressed("WeaponPrimary") and camera.fov == FOV_NORMAL:
shoot()
if event.is_action_pressed("WeaponReload"):
reload()
@ -412,6 +418,16 @@ func _unhandled_input(event):
rpc("switch_to_next_weapon")
if event.is_action_pressed("WeaponPrev"):
rpc("switch_to_prev_weapon")
if event.is_action_pressed("PlayerZoom"):
$Camera/ZoomTween.interpolate_property(camera, "fov", camera.fov, FOV_ZOOM, 0.25, Tween.TRANS_SINE, Tween.EASE_IN_OUT)
$Camera/ZoomTween.interpolate_property($HUD/Crosshair, "modulate", Color(1,1,1,1), Color(1,1,1,0), 0.25, Tween.TRANS_SINE, Tween.EASE_IN_OUT)
$Camera/ZoomTween.start()
elif event.is_action_released("PlayerZoom"):
$Camera/ZoomTween.interpolate_property(camera, "fov", camera.fov, FOV_NORMAL, 0.25, Tween.TRANS_SINE, Tween.EASE_IN_OUT)
$Camera/ZoomTween.interpolate_property($HUD/Crosshair, "modulate", Color(1,1,1,0), Color(1,1,1,1), 0.25, Tween.TRANS_SINE, Tween.EASE_IN_OUT)
$Camera/ZoomTween.start()
sync func set_jetpack_active(active):
jetpack_active = active

View File

@ -220,8 +220,10 @@ script = ExtResource( 8 )
[node name="Camera" type="Camera" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.53592, -0.0651628 )
[node name="ZoomTween" type="Tween" parent="Camera"]
[node name="Hand" type="Spatial" parent="Camera"]
transform = Transform( -4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, 0.335, -0.399925, -0.559 )
transform = Transform( -4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, 0.335, -0.390248, -0.559 )
[node name="WeaponBobAnimationTree" type="AnimationTree" parent="Camera/Hand"]
tree_root = SubResource( 12 )
@ -359,3 +361,5 @@ stream_paused = true
[node name="HUD" parent="." instance=ExtResource( 7 )]
visible = false
mouse_filter = 2
[editable path="HUD"]

View File

@ -119,6 +119,11 @@ Crouch={
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777238,"unicode":0,"echo":false,"script":null)
]
}
PlayerZoom={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":90,"unicode":0,"echo":false,"script":null)
]
}
[rendering]