|
@@ -20,7 +20,8 @@ export (float) var mouse_sensitivity_x = 0.3 #Mouse sensitivity X axis
|
|
|
export (float) var mouse_sensitivity_y = 0.3 #Mouse sensitivity Y axis
|
|
|
export (float) var mouse_max_up = 45 #Mouse max look angle up
|
|
|
export (float) var mouse_max_down = -50 #Mouse max look angle down
|
|
|
-export (float) var Jump_speed = 6 #Players jumps speed
|
|
|
+export (float) var jump_speed = 6 #Players jumps speed
|
|
|
+export (float) var jump_speed_sprint = 400 #Players jumps speed
|
|
|
export (bool) var allow_fall_input = true #Alow player to input movment when falling
|
|
|
export (bool) var stop_on_slope = false #Toggle sliding on slopes
|
|
|
export (float) var max_slides = 4 #Maximum of slides
|
|
@@ -29,13 +30,16 @@ export (bool) var infinite_inertia = false #Toggle infinite inertia
|
|
|
export (float) var gravaty = 1.625 #9.81 #Gravaty acceleration
|
|
|
#export (Vector3) var gravaty_vector = Vector3(0, -1, 0) #Gravaty normal direction vector
|
|
|
#export (Vector3) var floor_normal = Vector3(0, 1, 0) #Floor normal direction vector
|
|
|
-export (Vector3) var jump_vector = Vector3(0, 1, 0) #Jump normal direction vector
|
|
|
+#export (Vector3) var jump_vector = Vector3(0, 1, 0) #Jump normal direction vector
|
|
|
export (Vector3) var velocity = Vector3(0, 0, 0) #Initial velocity
|
|
|
|
|
|
onready var up = global_transform.origin.normalized()
|
|
|
onready var forward = global_transform.basis.y
|
|
|
onready var right = forward.cross(up).normalized()
|
|
|
|
|
|
+export (int) var move_mode = 0
|
|
|
+enum moveMode {MODE_NORMAL, MODE_HOVER, MODE_FLY}
|
|
|
+
|
|
|
func _ready():
|
|
|
if mouse_captured:
|
|
|
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
|
@@ -64,41 +68,46 @@ func _process(delta):
|
|
|
|
|
|
func _physics_process(delta):
|
|
|
|
|
|
- #player movement XY
|
|
|
- var dir = Vector3()
|
|
|
+
|
|
|
up = global_transform.origin.normalized()
|
|
|
right = forward.cross(up).normalized()
|
|
|
forward = up.cross(right).normalized()
|
|
|
transform.basis = Basis(right, up, -forward)
|
|
|
|
|
|
+ # we differentialte the y portion to apply a different speed (jump_speed)
|
|
|
+ var horDir = Vector3()
|
|
|
+ var vertDir = Vector3()
|
|
|
+ if move_mode == moveMode.MODE_FLY:
|
|
|
+ horDir = forward
|
|
|
+
|
|
|
if can_move and (is_on_floor() or allow_fall_input):
|
|
|
|
|
|
#Left
|
|
|
if Input.is_action_pressed("move_left"):
|
|
|
- dir -= right
|
|
|
+ horDir -= right
|
|
|
|
|
|
#Right
|
|
|
if Input.is_action_pressed("move_right"):
|
|
|
- dir += right
|
|
|
+ horDir += right
|
|
|
|
|
|
#Forward
|
|
|
if Input.is_action_pressed("move_forward"):
|
|
|
- dir += forward
|
|
|
+ horDir += forward
|
|
|
|
|
|
#Backwards
|
|
|
if Input.is_action_pressed("move_backward"):
|
|
|
- dir -= forward
|
|
|
+ horDir -= forward
|
|
|
|
|
|
# Jump
|
|
|
#if is_on_floor():
|
|
|
#if Input.is_action_pressed("move_up"):
|
|
|
# dir += up
|
|
|
if Input.is_action_pressed("move_down"):
|
|
|
- dir -= up
|
|
|
+ vertDir -= up
|
|
|
|
|
|
#Jump
|
|
|
if Input.is_action_pressed("move_up"):# and is_on_floor():
|
|
|
- velocity += up * Jump_speed - (up * -1).normalized() * velocity.dot(up * -1)
|
|
|
+ vertDir += up
|
|
|
|
|
|
#Sprint toggle
|
|
|
if can_sprint and Input.is_action_just_pressed("move_sprint"): #and is_on_floor():
|
|
@@ -106,10 +115,29 @@ func _physics_process(delta):
|
|
|
|
|
|
if can_sprint and not Input.is_action_pressed("move_sprint"): #and is_on_floor():
|
|
|
move_sprint = false
|
|
|
-
|
|
|
- velocity = velocity.linear_interpolate(dir * (move_speed_sprint if move_sprint else move_speed), move_acceleration * delta)
|
|
|
- if !is_on_floor():
|
|
|
- velocity -= up * gravaty
|
|
|
+
|
|
|
+ #Hover toggle
|
|
|
+ if Input.is_action_just_pressed("hover_mode"):
|
|
|
+ if move_mode != moveMode.MODE_HOVER:
|
|
|
+ move_mode = moveMode.MODE_HOVER
|
|
|
+ else:
|
|
|
+ move_mode = moveMode.MODE_NORMAL
|
|
|
+
|
|
|
+ #Fly toggle
|
|
|
+ if Input.is_action_just_pressed("fly_mode"):
|
|
|
+ if move_mode != moveMode.MODE_FLY:
|
|
|
+ move_mode = moveMode.MODE_FLY
|
|
|
+ else:
|
|
|
+ move_mode = moveMode.MODE_NORMAL
|
|
|
+
|
|
|
+
|
|
|
+ if not (move_mode == moveMode.MODE_NORMAL and horDir+vertDir == Vector3(0, 0, 0)):
|
|
|
+ velocity = velocity.linear_interpolate(horDir * (move_speed_sprint if move_sprint else move_speed)
|
|
|
+ + vertDir * (jump_speed_sprint if move_sprint else jump_speed), move_acceleration * delta)
|
|
|
+
|
|
|
+ #velocity = velocity.linear_interpolate(vertDir * (jump_speed_sprint if move_sprint else jump_speed), move_acceleration * delta)
|
|
|
+ #if !is_on_floor():
|
|
|
+ #velocity -= up * gravaty
|
|
|
velocity = move_and_slide(velocity, up)
|
|
|
|
|
|
|