Zoom the view with "z" key - it's not possible to shoot while zoomed in (to avoid sniping with all weapons).
parent
d2a1c7e121
commit
40079d2b0a
|
@ -1,6 +1,9 @@
|
||||||
class_name Player
|
class_name Player
|
||||||
extends KinematicBody
|
extends KinematicBody
|
||||||
|
|
||||||
|
const FOV_NORMAL = 70
|
||||||
|
const FOV_ZOOM = 25
|
||||||
|
|
||||||
const GRAVITY = Vector3.DOWN * 9.8 * 1.5
|
const GRAVITY = Vector3.DOWN * 9.8 * 1.5
|
||||||
const UP = Vector3.UP
|
const UP = Vector3.UP
|
||||||
const JUMP_VELOCITY = 8
|
const JUMP_VELOCITY = 8
|
||||||
|
@ -203,7 +206,8 @@ remote func mouselook_abs(x, y):
|
||||||
rotation.y = y
|
rotation.y = y
|
||||||
|
|
||||||
remote func mouselook(rel):
|
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)
|
rotate_y(- rel.x * sensitivity)
|
||||||
camera.rotation.x = clamp(camera.rotation.x-rel.y * sensitivity, -PI/2, PI/2)
|
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
|
is_dead = false
|
||||||
for i in $Camera/Hand/Weapons.get_children():
|
for i in $Camera/Hand/Weapons.get_children():
|
||||||
i.reset()
|
i.reset()
|
||||||
|
$HUD/Crosshair.modulate = Color(1,1,1,1)
|
||||||
|
camera.fov = FOV_NORMAL
|
||||||
|
|
||||||
func shoot():
|
func shoot():
|
||||||
# The underscore indicates an unused variable.
|
# The underscore indicates an unused variable.
|
||||||
|
@ -403,7 +409,7 @@ func _unhandled_input(event):
|
||||||
rpc("set_jetpack_active", false)
|
rpc("set_jetpack_active", false)
|
||||||
|
|
||||||
# Weapon
|
# Weapon
|
||||||
if event.is_action_pressed("WeaponPrimary"):
|
if event.is_action_pressed("WeaponPrimary") and camera.fov == FOV_NORMAL:
|
||||||
shoot()
|
shoot()
|
||||||
if event.is_action_pressed("WeaponReload"):
|
if event.is_action_pressed("WeaponReload"):
|
||||||
reload()
|
reload()
|
||||||
|
@ -412,6 +418,16 @@ func _unhandled_input(event):
|
||||||
rpc("switch_to_next_weapon")
|
rpc("switch_to_next_weapon")
|
||||||
if event.is_action_pressed("WeaponPrev"):
|
if event.is_action_pressed("WeaponPrev"):
|
||||||
rpc("switch_to_prev_weapon")
|
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):
|
sync func set_jetpack_active(active):
|
||||||
jetpack_active = active
|
jetpack_active = active
|
||||||
|
|
|
@ -220,8 +220,10 @@ script = ExtResource( 8 )
|
||||||
[node name="Camera" type="Camera" parent="."]
|
[node name="Camera" type="Camera" parent="."]
|
||||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.53592, -0.0651628 )
|
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"]
|
[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"]
|
[node name="WeaponBobAnimationTree" type="AnimationTree" parent="Camera/Hand"]
|
||||||
tree_root = SubResource( 12 )
|
tree_root = SubResource( 12 )
|
||||||
|
@ -359,3 +361,5 @@ stream_paused = true
|
||||||
[node name="HUD" parent="." instance=ExtResource( 7 )]
|
[node name="HUD" parent="." instance=ExtResource( 7 )]
|
||||||
visible = false
|
visible = false
|
||||||
mouse_filter = 2
|
mouse_filter = 2
|
||||||
|
|
||||||
|
[editable path="HUD"]
|
||||||
|
|
|
@ -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)
|
"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]
|
[rendering]
|
||||||
|
|
||||||
|
|
Reference in New Issue