Selaa lähdekoodia

add alternative movement modes

Malf 2 vuotta sitten
vanhempi
commit
f7227eaefb
5 muutettua tiedostoa jossa 90 lisäystä ja 47 poistoa
  1. 1 1
      .gitignore
  2. 3 32
      Main.tscn
  3. 42 14
      Player.gd
  4. 34 0
      Player.tscn
  5. 10 0
      project.godot

+ 1 - 1
.gitignore

@@ -1,4 +1,4 @@
-tex/
 *.tar.gz
 .import/
+*.import
 test.tscn

+ 3 - 32
Main.tscn

@@ -1,7 +1,7 @@
-[gd_scene load_steps=13 format=2]
+[gd_scene load_steps=11 format=2]
 
 [ext_resource path="res://Main.gd" type="Script" id=1]
-[ext_resource path="res://Player.gd" type="Script" id=2]
+[ext_resource path="res://Player.tscn" type="PackedScene" id=2]
 [ext_resource path="res://ChunkSystem.gd" type="Script" id=3]
 [ext_resource path="res://tex/eso.jpg" type="Texture" id=4]
 [ext_resource path="res://shader/ground_shader.tres" type="Material" id=5]
@@ -17,10 +17,6 @@ ambient_light_color = Color( 1, 1, 1, 1 )
 tonemap_mode = 3
 glow_enabled = true
 
-[sub_resource type="CapsuleShape" id=8]
-
-[sub_resource type="CapsuleMesh" id=7]
-
 [sub_resource type="SpatialMaterial" id=6]
 albedo_color = Color( 0.168627, 0.164706, 0.913725, 1 )
 detail_enabled = true
@@ -49,32 +45,7 @@ environment = SubResource( 10 )
 transform = Transform( 1, 0, 0, 0, 0.81189, 0.583811, 0, -0.583811, 0.81189, 14.964, 0, 0 )
 visible = false
 
-[node name="Player" type="KinematicBody" parent="."]
-script = ExtResource( 2 )
-
-[node name="Camera" type="Camera" parent="Player"]
-transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.67414, -1.02577 )
-far = 50000.0
-
-[node name="CollisionShape" type="CollisionShape" parent="Player"]
-transform = Transform( 1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0 )
-shape = SubResource( 8 )
-
-[node name="OmniLight" type="OmniLight" parent="Player"]
-transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.317136, 0.127762 )
-visible = false
-light_energy = 11.83
-
-[node name="MeshInstance" type="MeshInstance" parent="Player"]
-transform = Transform( 1, 0, 0, 0, -0.0140669, 0.999901, 0, -0.999901, -0.0140669, 0, 0, 0 )
-mesh = SubResource( 7 )
-material/0 = null
-
-[node name="SpotLight" type="SpotLight" parent="Player/MeshInstance"]
-transform = Transform( 1, 0, 0, 0, 0.573905, -0.818922, 0, 0.818922, 0.573905, -0.00356923, 0.433873, 1.27676 )
-light_color = Color( 0.552941, 0.482353, 0.298039, 1 )
-spot_range = 179.547
-spot_angle = 33.3247
+[node name="Player" parent="." instance=ExtResource( 2 )]
 
 [node name="Chunks" type="Spatial" parent="."]
 script = ExtResource( 3 )

+ 42 - 14
Player.gd

@@ -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)
 	
 	

+ 34 - 0
Player.tscn

@@ -0,0 +1,34 @@
+[gd_scene load_steps=4 format=2]
+
+[ext_resource path="res://Player.gd" type="Script" id=1]
+
+[sub_resource type="CapsuleShape" id=8]
+
+[sub_resource type="CapsuleMesh" id=7]
+
+[node name="Player" type="KinematicBody"]
+script = ExtResource( 1 )
+
+[node name="Camera" type="Camera" parent="."]
+transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.67414, -1.02577 )
+far = 50000.0
+
+[node name="CollisionShape" type="CollisionShape" parent="."]
+transform = Transform( 1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0 )
+shape = SubResource( 8 )
+
+[node name="OmniLight" type="OmniLight" parent="."]
+transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.317136, 0.127762 )
+visible = false
+light_energy = 11.83
+
+[node name="MeshInstance" type="MeshInstance" parent="."]
+transform = Transform( 1, 0, 0, 0, -0.0140669, 0.999901, 0, -0.999901, -0.0140669, 0, 0, 0 )
+mesh = SubResource( 7 )
+material/0 = null
+
+[node name="SpotLight" type="SpotLight" parent="MeshInstance"]
+transform = Transform( 1, 0, 0, 0, 0.573905, -0.818922, 0, 0.818922, 0.573905, -0.00356923, 0.433873, 1.27676 )
+light_color = Color( 0.552941, 0.482353, 0.298039, 1 )
+spot_range = 179.547
+spot_angle = 33.3247

+ 10 - 0
project.godot

@@ -60,6 +60,16 @@ click={
 "events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":1,"pressed":false,"doubleclick":false,"script":null)
  ]
 }
+hover_mode={
+"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":0,"physical_scancode":72,"unicode":0,"echo":false,"script":null)
+ ]
+}
+fly_mode={
+"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":0,"physical_scancode":70,"unicode":0,"echo":false,"script":null)
+ ]
+}
 
 [physics]