Browse Source

improve moveModes

Malf 2 years ago
parent
commit
7939f27ad2
1 changed files with 26 additions and 10 deletions
  1. 26 10
      Player.gd

+ 26 - 10
Player.gd

@@ -11,8 +11,9 @@ extends KinematicBody
 export (bool) var can_move = true #Alow player to input movment.
 export (bool) var can_sprint = true #Alow player to toggle sprint movment.
 export (float) var move_speed = 8 #Players movement speed
-export (float) var move_speed_sprint = 600#16 #Players sprint movement speed
+export (float) var move_speed_sprint = 16#16 #Players sprint movement speed
 export (bool) var move_sprint = false #Player sprinting toggle
+export (float) var move_speed_max = 200 #Player maximum velocity
 export (float) var move_acceleration = 7 #Players acceleration to movment speed
 export (float) var move_deacceleration = 10 #Players deacceleration from movment speed
 export (bool) var mouse_captured = true #Toggles mouse captured mode
@@ -21,7 +22,7 @@ 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_sprint = 400 #Players jumps speed
+export (float) var jump_speed_sprint = 12 #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
@@ -59,7 +60,8 @@ func _process(delta):
 	var pos = self.global_transform.origin
 	.get_parent().get_node("UI/1").text="x:%s y:%s z:%s" %[pos.x, pos.y, pos.z]
 	.get_parent().get_node("UI/2").text="latlonhight: "+str(getSpos())+","+str(pos.length())
-	#.get_parent().get_node("UI/4").text="chunkDist: %s" % get_node("/Tiles").get_child(0).get_global_transform().origin
+	.get_parent().get_node("UI/3").text="vel: %s" % velocity
+	.get_parent().get_node("UI/4").text="mode: %s" % move_mode
 
 	#floor_normal = pos.normalized()
 	#gravaty_vector = floor_normal * -1
@@ -77,8 +79,11 @@ func _physics_process(delta):
 	# 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
+	match move_mode:
+		moveMode.MODE_FLY:
+			horDir = forward
+		moveMode.MODE_HOVER:
+			horDir = -velocity * 0.5
 	
 	if can_move and (is_on_floor() or allow_fall_input):
 		
@@ -112,9 +117,11 @@ func _physics_process(delta):
 		#Sprint toggle
 		if can_sprint and Input.is_action_just_pressed("move_sprint"): #and is_on_floor():
 			move_sprint = true
+			move_speed_max = 600
 			
 		if can_sprint and not Input.is_action_pressed("move_sprint"): #and is_on_floor():
 			move_sprint = false
+			move_speed_max = 200
 			
 		#Hover toggle
 		if Input.is_action_just_pressed("hover_mode"):
@@ -128,16 +135,25 @@ func _physics_process(delta):
 			if move_mode != moveMode.MODE_FLY:
 				move_mode = moveMode.MODE_FLY
 			else:
-				move_mode = moveMode.MODE_NORMAL
-		
+				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)
+	if move_mode == moveMode.MODE_NORMAL and horDir+vertDir == Vector3(0, 0, 0):
+		# in NORMAL MODE velocity stays unchanged without input
+		pass
+	else:
+		#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 += (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
+		
+	# limit Speed
+	if velocity.length() > move_speed_max:
+		velocity = velocity.normalized() * move_speed_max
+
 	velocity = move_and_slide(velocity, up)