added look stuff
This commit is contained in:
@ -1,6 +1,16 @@
|
|||||||
extends Node3D
|
extends Node3D
|
||||||
|
|
||||||
@export var vertical_joystick_sensitity : float = 2
|
@export var vertical_joystick_sensitity : float = 2
|
||||||
|
@export var vertical_mouse_sensitivity : float = 0.02
|
||||||
|
|
||||||
|
func can_look(amount, sensitivity):
|
||||||
|
var current_rotation_x = global_rotation_degrees.x
|
||||||
|
var amount_to_move = amount * vertical_mouse_sensitivity
|
||||||
|
var angle_after_move = current_rotation_x + amount_to_move
|
||||||
|
if angle_after_move >= -85 and angle_after_move <= 85:
|
||||||
|
return true
|
||||||
|
else:
|
||||||
|
false
|
||||||
|
|
||||||
func _process(delta):
|
func _process(delta):
|
||||||
var look_velocity = Input.get_vector("look_left", "look_right", "look_up", "look_down")
|
var look_velocity = Input.get_vector("look_left", "look_right", "look_up", "look_down")
|
||||||
@ -8,4 +18,6 @@ func _process(delta):
|
|||||||
|
|
||||||
func _unhandled_input(event):
|
func _unhandled_input(event):
|
||||||
if event is InputEventMouseMotion:
|
if event is InputEventMouseMotion:
|
||||||
rotate_x(-event.relative.y * 0.02 )
|
self.rotate_x(-event.relative.y * vertical_mouse_sensitivity )
|
||||||
|
print(global_rotation_degrees.x)
|
||||||
|
|
||||||
|
|||||||
@ -6,6 +6,24 @@ enum CONDITION {NORMAL, SPRINTING, VAPING, COUGHING, SEVERE_COUGHING}
|
|||||||
func set_condition(con):
|
func set_condition(con):
|
||||||
current_condition = con
|
current_condition = con
|
||||||
print("Setting Condition to ", con)
|
print("Setting Condition to ", con)
|
||||||
|
match con:
|
||||||
|
CONDITION.VAPING:
|
||||||
|
vapes_per_min += 1
|
||||||
|
$Node3D/VapeLight.on()
|
||||||
|
$"Coughing Timer".start()
|
||||||
|
$"Severe Coughing Timer".start()
|
||||||
|
CONDITION.NORMAL:
|
||||||
|
$Node3D/VapeLight.off()
|
||||||
|
$"Coughing Timer".stop()
|
||||||
|
$"Severe Coughing Timer".stop()
|
||||||
|
CONDITION.COUGHING:
|
||||||
|
$Node3D/VapeLight.off()
|
||||||
|
$"Coughing Recovery".start()
|
||||||
|
$"Severe Coughing Timer".stop()
|
||||||
|
CONDITION.SEVERE_COUGHING:
|
||||||
|
$Node3D/VapeLight.off()
|
||||||
|
$"Severe Coughing Recovery".start()
|
||||||
|
$"Coughing Timer".stop()
|
||||||
|
|
||||||
var will_cough = false
|
var will_cough = false
|
||||||
var timealive = 0
|
var timealive = 0
|
||||||
@ -22,58 +40,51 @@ const JUMP_VELOCITY = 4.5
|
|||||||
#Looking Variables
|
#Looking Variables
|
||||||
var mouse_sensitivity = 0.02
|
var mouse_sensitivity = 0.02
|
||||||
var joystick_sensitity = 2
|
var joystick_sensitity = 2
|
||||||
var prev_mouse_location = Vector2()
|
|
||||||
|
|
||||||
|
|
||||||
|
var is_paused = false
|
||||||
|
|
||||||
# Get the gravity from the project settings to be synced with RigidBody nodes.
|
# Get the gravity from the project settings to be synced with RigidBody nodes.
|
||||||
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
|
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
|
||||||
|
|
||||||
|
|
||||||
func _physics_process(delta):
|
func _physics_process(delta):
|
||||||
match current_condition:
|
if not is_paused:
|
||||||
CONDITION.NORMAL:
|
match current_condition:
|
||||||
current_speed = SPEED_NORMAL
|
CONDITION.NORMAL:
|
||||||
CONDITION.SPRINTING:
|
current_speed = SPEED_NORMAL
|
||||||
current_speed = SPEED_SPRINTING
|
CONDITION.SPRINTING:
|
||||||
CONDITION.VAPING:
|
current_speed = SPEED_SPRINTING
|
||||||
current_speed = SPEED_VAPING
|
CONDITION.VAPING:
|
||||||
CONDITION.COUGHING:
|
current_speed = SPEED_VAPING
|
||||||
current_speed = SPEED_SLOWED
|
CONDITION.COUGHING:
|
||||||
CONDITION.SEVERE_COUGHING:
|
current_speed = SPEED_SLOWED
|
||||||
current_speed = SPEED_IMMOBILE
|
CONDITION.SEVERE_COUGHING:
|
||||||
|
current_speed = SPEED_IMMOBILE
|
||||||
# Add the gravity.
|
|
||||||
if not is_on_floor():
|
|
||||||
velocity.y -= gravity * delta
|
|
||||||
|
|
||||||
# Handle jump.
|
|
||||||
if Input.is_action_just_pressed("ui_accept") and is_on_floor() and current_condition == CONDITION.NORMAL or current_condition == CONDITION.SPRINTING:
|
|
||||||
velocity.y = JUMP_VELOCITY
|
|
||||||
|
|
||||||
# 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("move_left", "move_right", "move_forward", "move_back")
|
|
||||||
var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
|
|
||||||
if direction:
|
|
||||||
velocity.x = direction.x * current_speed
|
|
||||||
velocity.z = direction.z * current_speed
|
|
||||||
else:
|
|
||||||
velocity.x = move_toward(velocity.x, 0, current_speed)
|
|
||||||
velocity.z = move_toward(velocity.z, 0, current_speed)
|
|
||||||
|
|
||||||
|
# Add the gravity.
|
||||||
move_and_slide()
|
if not is_on_floor():
|
||||||
|
velocity.y -= gravity * delta
|
||||||
|
|
||||||
var look_velocity = Input.get_vector("look_left", "look_right", "look_up", "look_down")
|
# Handle jump.
|
||||||
rotate_y(-look_velocity.x * joystick_sensitity * delta)
|
if Input.is_action_just_pressed("ui_accept") and is_on_floor() and current_condition != CONDITION.COUGHING and current_condition != CONDITION.SEVERE_COUGHING:
|
||||||
|
velocity.y = JUMP_VELOCITY
|
||||||
|
|
||||||
#Look mouse controls left and right
|
# Get the input direction and handle the movement/deceleration.
|
||||||
func _unhandled_input(event):
|
# As good practice, you should replace UI actions with custom gameplay actions.
|
||||||
if event is InputEventMouseMotion:
|
var input_dir = Input.get_vector("move_left", "move_right", "move_forward", "move_back")
|
||||||
rotate_y(-event.relative.x * mouse_sensitivity)
|
var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
|
||||||
|
if direction:
|
||||||
|
velocity.x = direction.x * current_speed
|
||||||
|
velocity.z = direction.z * current_speed
|
||||||
|
else:
|
||||||
|
velocity.x = move_toward(velocity.x, 0, current_speed)
|
||||||
|
velocity.z = move_toward(velocity.z, 0, current_speed)
|
||||||
|
|
||||||
|
|
||||||
|
move_and_slide()
|
||||||
|
|
||||||
|
var look_velocity = Input.get_vector("look_left", "look_right", "look_up", "look_down")
|
||||||
|
rotate_y(-look_velocity.x * joystick_sensitity * delta)
|
||||||
|
|
||||||
|
|
||||||
func _process(delta):
|
func _process(delta):
|
||||||
#Calculations for seeing if you vaped too many times within a short span
|
#Calculations for seeing if you vaped too many times within a short span
|
||||||
timealive += delta
|
timealive += delta
|
||||||
@ -84,34 +95,28 @@ func _process(delta):
|
|||||||
vapes_per_min = 0
|
vapes_per_min = 0
|
||||||
|
|
||||||
func _input(event):
|
func _input(event):
|
||||||
if event.is_action_pressed("vape"):
|
if not is_paused:
|
||||||
if current_condition == CONDITION.NORMAL:
|
if event is InputEventMouseMotion:
|
||||||
vapes_per_min += 1
|
rotate_y(-event.relative.x * mouse_sensitivity)
|
||||||
set_condition(CONDITION.VAPING)
|
|
||||||
$"Coughing Timer".start()
|
if event.is_action_pressed("vape"):
|
||||||
$"Severe Coughing Timer".start()
|
if current_condition == CONDITION.NORMAL:
|
||||||
$Node3D/VapeLight.on()
|
set_condition(CONDITION.VAPING)
|
||||||
|
|
||||||
if event.is_action_released("vape"):
|
if event.is_action_released("vape"):
|
||||||
$Node3D/VapeLight.off()
|
if current_condition == CONDITION.VAPING:
|
||||||
if current_condition == CONDITION.VAPING:
|
if will_cough and current_condition != CONDITION.SEVERE_COUGHING:
|
||||||
if will_cough and current_condition != CONDITION.SEVERE_COUGHING:
|
set_condition(CONDITION.COUGHING)
|
||||||
set_condition(CONDITION.COUGHING)
|
else:
|
||||||
# Play Coughing Sound
|
set_condition(CONDITION.NORMAL)
|
||||||
$"Coughing Recovery".start()
|
|
||||||
$"Severe Coughing Timer".stop()
|
|
||||||
else:
|
|
||||||
set_condition(CONDITION.NORMAL)
|
|
||||||
$"Coughing Timer".stop()
|
|
||||||
$"Severe Coughing Timer".stop()
|
|
||||||
|
|
||||||
if event.is_action_pressed("sprint"):
|
if event.is_action_pressed("sprint"):
|
||||||
if current_condition == CONDITION.NORMAL:
|
if current_condition == CONDITION.NORMAL:
|
||||||
set_condition(CONDITION.SPRINTING)
|
set_condition(CONDITION.SPRINTING)
|
||||||
|
|
||||||
if event.is_action_released("sprint"):
|
if event.is_action_released("sprint"):
|
||||||
if current_condition == CONDITION.SPRINTING:
|
if current_condition == CONDITION.SPRINTING:
|
||||||
set_condition(CONDITION.NORMAL)
|
set_condition(CONDITION.NORMAL)
|
||||||
|
|
||||||
func recover():
|
func recover():
|
||||||
will_cough = false
|
will_cough = false
|
||||||
@ -121,7 +126,6 @@ func recover():
|
|||||||
CONDITION.SEVERE_COUGHING:
|
CONDITION.SEVERE_COUGHING:
|
||||||
set_condition(CONDITION.NORMAL)
|
set_condition(CONDITION.NORMAL)
|
||||||
|
|
||||||
|
|
||||||
#Timers
|
#Timers
|
||||||
func _on_coughing_timer_timeout():
|
func _on_coughing_timer_timeout():
|
||||||
will_cough = true
|
will_cough = true
|
||||||
|
|||||||
Reference in New Issue
Block a user