Prechádzať zdrojové kódy

Merge pull request #52 from aaronfranke/player

Player movement, camera, and respawn code
Aaron Franke 5 rokov pred
rodič
commit
47ab74cef4

+ 14 - 3
enemies/red_robot/red_robot.tscn

@@ -192,7 +192,7 @@ nodes/hit3/position = Vector2( 980, 240 )
 nodes/output/position = Vector2( 1180, 200 )
 nodes/output/position = Vector2( 1180, 200 )
 nodes/state/node = SubResource( 25 )
 nodes/state/node = SubResource( 25 )
 nodes/state/position = Vector2( 60, 100 )
 nodes/state/position = Vector2( 60, 100 )
-node_connections = [ "output", 0, "hit3", "state", 0, "Animation", "state", 1, "Animation 3", "state", 2, "Animation 2", "state", 3, "Animation 4", "hit2", 0, "hit1", "hit2", 1, "Animation 6", "hit3", 0, "hit2", "hit3", 1, "Animation 7", "aiming", 0, "state", "aiming", 1, "aim", "hit1", 0, "aiming", "hit1", 1, "Animation 5" ]
+node_connections = [ "output", 0, "hit3", "state", 0, "Animation", "state", 1, "Animation 3", "state", 2, "Animation 2", "state", 3, "Animation 4", "aiming", 0, "state", "aiming", 1, "aim", "hit1", 0, "aiming", "hit1", 1, "Animation 5", "hit2", 0, "hit1", "hit2", 1, "Animation 6", "hit3", 0, "hit2", "hit3", 1, "Animation 7" ]
 
 
 [sub_resource type="SphereShape" id=27]
 [sub_resource type="SphereShape" id=27]
 radius = 1.11815
 radius = 1.11815
@@ -542,13 +542,18 @@ tracks/10/keys = {
 [sub_resource type="AudioStreamRandomPitch" id=44]
 [sub_resource type="AudioStreamRandomPitch" id=44]
 audio_stream = ExtResource( 18 )
 audio_stream = ExtResource( 18 )
 
 
-[node name="big_robot" type="KinematicBody"]
+[node name="RedRobot" type="KinematicBody"]
+collision_layer = 3
+collision_mask = 3
 script = ExtResource( 1 )
 script = ExtResource( 1 )
 
 
 [node name="Scene Root" parent="." instance=ExtResource( 2 )]
 [node name="Scene Root" parent="." instance=ExtResource( 2 )]
 
 
+[node name="Skeleton" parent="Scene Root/Armature" index="0"]
+bones/14/bound_children = [ NodePath("ray_from") ]
+
 [node name="ray_from" type="BoneAttachment" parent="Scene Root/Armature/Skeleton" index="4"]
 [node name="ray_from" type="BoneAttachment" parent="Scene Root/Armature/Skeleton" index="4"]
-transform = Transform( -0.999975, 0.0070746, 0.000551782, 0.00707948, 0.999931, 0.0094271, -0.000485051, 0.00943077, -0.999955, 0.00850569, 2.08377, 0.183162 )
+transform = Transform( -0.862541, 0.0793345, -0.499729, -0.033231, 0.976617, 0.2124, 0.504895, 0.19981, -0.839736, 0.123715, 2.00738, 0.252644 )
 bone_name = "CannonAnimRecoil"
 bone_name = "CannonAnimRecoil"
 
 
 [node name="ray" type="MeshInstance" parent="Scene Root/Armature/Skeleton/ray_from"]
 [node name="ray" type="MeshInstance" parent="Scene Root/Armature/Skeleton/ray_from"]
@@ -631,6 +636,8 @@ visible = false
 
 
 [node name="part_shield1" type="RigidBody" parent="death"]
 [node name="part_shield1" type="RigidBody" parent="death"]
 transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -1.37822, 1.11034, 1.09121 )
 transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -1.37822, 1.11034, 1.09121 )
+collision_layer = 3
+collision_mask = 3
 mode = 1
 mode = 1
 physics_material_override = SubResource( 30 )
 physics_material_override = SubResource( 30 )
 
 
@@ -666,6 +673,8 @@ color_ramp = SubResource( 35 )
 
 
 [node name="part_shield2" type="RigidBody" parent="death"]
 [node name="part_shield2" type="RigidBody" parent="death"]
 transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 1.75083, 1.02975, 0.162546 )
 transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 1.75083, 1.02975, 0.162546 )
+collision_layer = 3
+collision_mask = 3
 mode = 1
 mode = 1
 physics_material_override = SubResource( 36 )
 physics_material_override = SubResource( 36 )
 
 
@@ -701,6 +710,8 @@ color_ramp = SubResource( 35 )
 
 
 [node name="part_shield3" type="RigidBody" parent="death"]
 [node name="part_shield3" type="RigidBody" parent="death"]
 transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.0374503, 1.02975, 0.162546 )
 transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.0374503, 1.02975, 0.162546 )
+collision_layer = 3
+collision_mask = 3
 mode = 1
 mode = 1
 physics_material_override = SubResource( 39 )
 physics_material_override = SubResource( 39 )
 angular_damp = 0.3
 angular_damp = 0.3

+ 7 - 7
level/level.tscn

@@ -206,10 +206,10 @@ transform = Transform( 1, 0, 7.45058e-09, 5.72164e-11, 1, 8.73443e-11, -1.49012e
 [node name="WorldEnvironment" type="WorldEnvironment" parent="."]
 [node name="WorldEnvironment" type="WorldEnvironment" parent="."]
 environment = SubResource( 1 )
 environment = SubResource( 1 )
 
 
-[node name="shader_cache" type="Node" parent="WorldEnvironment"]
+[node name="ShaderCache" type="Node" parent="WorldEnvironment"]
 script = ExtResource( 3 )
 script = ExtResource( 3 )
 
 
-[node name="bullet" parent="WorldEnvironment/shader_cache" instance=ExtResource( 4 )]
+[node name="Bullet" parent="WorldEnvironment/ShaderCache" instance=ExtResource( 4 )]
 
 
 [node name="GIProbe" type="GIProbe" parent="."]
 [node name="GIProbe" type="GIProbe" parent="."]
 transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -6.09263, 1.28266, 2.88598 )
 transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -6.09263, 1.28266, 2.88598 )
@@ -220,19 +220,19 @@ propagation = 1.0
 interior = true
 interior = true
 data = ExtResource( 5 )
 data = ExtResource( 5 )
 
 
-[node name="player" parent="." instance=ExtResource( 6 )]
+[node name="Player" parent="." instance=ExtResource( 6 )]
 transform = Transform( -0.575826, 0, -0.817573, 0, 1, 0, 0.817573, 0, -0.575826, 64.8183, -1.0765, 78.7639 )
 transform = Transform( -0.575826, 0, -0.817573, 0, 1, 0, 0.817573, 0, -0.575826, 64.8183, -1.0765, 78.7639 )
 
 
-[node name="big_robot" parent="." instance=ExtResource( 7 )]
+[node name="RedRobot1" parent="." instance=ExtResource( 7 )]
 transform = Transform( 0.843905, 0, -0.536493, 0, 1, 0, 0.536493, 0, 0.843905, 71.5907, -6.05686, 46.2736 )
 transform = Transform( 0.843905, 0, -0.536493, 0, 1, 0, 0.536493, 0, 0.843905, 71.5907, -6.05686, 46.2736 )
 
 
-[node name="big_robot2" parent="." instance=ExtResource( 7 )]
+[node name="RedRobot2" parent="." instance=ExtResource( 7 )]
 transform = Transform( 0.338334, 0, 0.941027, 0, 1, 0, -0.941027, 0, 0.338334, 53.2126, -6.05686, 15.9321 )
 transform = Transform( 0.338334, 0, 0.941027, 0, 1, 0, -0.941027, 0, 0.338334, 53.2126, -6.05686, 15.9321 )
 
 
-[node name="big_robot3" parent="." instance=ExtResource( 7 )]
+[node name="RedRobot3" parent="." instance=ExtResource( 7 )]
 transform = Transform( -0.164432, 0, 0.986389, 0, 1, 0, -0.986389, 0, -0.164432, -2.96096, -11.6923, 20.2343 )
 transform = Transform( -0.164432, 0, 0.986389, 0, 1, 0, -0.986389, 0, -0.164432, -2.96096, -11.6923, 20.2343 )
 
 
-[node name="big_robot4" parent="." instance=ExtResource( 7 )]
+[node name="RedRobot4" parent="." instance=ExtResource( 7 )]
 transform = Transform( -0.164432, 0, 0.986389, 0, 1, 0, -0.986389, 0, -0.164432, -9.15526, -11.6923, -16.9238 )
 transform = Transform( -0.164432, 0, 0.986389, 0, 1, 0, -0.986389, 0, -0.164432, -9.15526, -11.6923, -16.9238 )
 
 
 [node name="sound_outside" type="Area" parent="."]
 [node name="sound_outside" type="Area" parent="."]

+ 2 - 2
level/shader_cache.gd

@@ -4,7 +4,7 @@ var fade_in_frame_counter = 60
 
 
 func _ready():
 func _ready():
 	# We don't want the cache bullet to make noise. So just get rid of its audio.
 	# We don't want the cache bullet to make noise. So just get rid of its audio.
-	$bullet/explosion2.queue_free()
+	$Bullet/ExplosionAudio.queue_free()
 
 
 
 
 func _physics_process(_delta):
 func _physics_process(_delta):
@@ -12,7 +12,7 @@ func _physics_process(_delta):
 	# Fade in progressively to hide artifacts.
 	# Fade in progressively to hide artifacts.
 	if fade_in_frame_counter == 50:
 	if fade_in_frame_counter == 50:
 		# Hide after a few frames to be sure the shaders compiled.
 		# Hide after a few frames to be sure the shaders compiled.
-		$bullet.hide()
+		$Bullet.hide()
 	if fade_in_frame_counter == 0:
 	if fade_in_frame_counter == 0:
 		# This node has served its purpose, and now it's time to stop existing.
 		# This node has served its purpose, and now it's time to stop existing.
 		self.queue_free()
 		self.queue_free()

+ 2 - 2
player/bullet.gd

@@ -13,13 +13,13 @@ func _process(delta):
 	time_alive -= delta
 	time_alive -= delta
 	if time_alive < 0:
 	if time_alive < 0:
 		hit = true
 		hit = true
-		$anim.play("explode")
+		$AnimationPlayer.play("explode")
 	var col = move_and_collide(delta * direction * BULLET_VELOCITY)
 	var col = move_and_collide(delta * direction * BULLET_VELOCITY)
 	if col:
 	if col:
 		if col.collider and col.collider.has_method("hit"):
 		if col.collider and col.collider.has_method("hit"):
 			col.collider.hit()
 			col.collider.hit()
 		$CollisionShape.disabled = true
 		$CollisionShape.disabled = true
-		$anim.play("explode")
+		$AnimationPlayer.play("explode")
 		hit = true
 		hit = true
 
 
 
 

+ 6 - 6
player/bullet.tscn

@@ -95,7 +95,7 @@ material = SubResource( 15 )
 resource_name = "explode"
 resource_name = "explode"
 length = 3.0
 length = 3.0
 tracks/0/type = "value"
 tracks/0/type = "value"
-tracks/0/path = NodePath("explosion:emitting")
+tracks/0/path = NodePath("Explosion:emitting")
 tracks/0/interp = 1
 tracks/0/interp = 1
 tracks/0/loop_wrap = true
 tracks/0/loop_wrap = true
 tracks/0/imported = false
 tracks/0/imported = false
@@ -157,7 +157,7 @@ tracks/4/keys = {
 "values": [ false ]
 "values": [ false ]
 }
 }
 tracks/5/type = "value"
 tracks/5/type = "value"
-tracks/5/path = NodePath("explosion2:playing")
+tracks/5/path = NodePath("ExplosionAudio:playing")
 tracks/5/interp = 1
 tracks/5/interp = 1
 tracks/5/loop_wrap = true
 tracks/5/loop_wrap = true
 tracks/5/imported = false
 tracks/5/imported = false
@@ -169,7 +169,7 @@ tracks/5/keys = {
 "values": [ true ]
 "values": [ true ]
 }
 }
 
 
-[node name="bullet" type="KinematicBody"]
+[node name="Bullet" type="KinematicBody"]
 script = ExtResource( 1 )
 script = ExtResource( 1 )
 
 
 [node name="MeshInstance" type="MeshInstance" parent="."]
 [node name="MeshInstance" type="MeshInstance" parent="."]
@@ -198,16 +198,16 @@ omni_shadow_mode = 0
 [node name="CollisionShape" type="CollisionShape" parent="."]
 [node name="CollisionShape" type="CollisionShape" parent="."]
 shape = SubResource( 9 )
 shape = SubResource( 9 )
 
 
-[node name="explosion" type="Particles" parent="."]
+[node name="Explosion" type="Particles" parent="."]
 emitting = false
 emitting = false
 amount = 6
 amount = 6
 explosiveness = 1.0
 explosiveness = 1.0
 process_material = SubResource( 14 )
 process_material = SubResource( 14 )
 draw_pass_1 = SubResource( 16 )
 draw_pass_1 = SubResource( 16 )
 
 
-[node name="anim" type="AnimationPlayer" parent="."]
+[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
 anims/explode = SubResource( 17 )
 anims/explode = SubResource( 17 )
 
 
-[node name="explosion2" type="AudioStreamPlayer3D" parent="."]
+[node name="ExplosionAudio" type="AudioStreamPlayer3D" parent="."]
 stream = ExtResource( 3 )
 stream = ExtResource( 3 )
 unit_size = 20.0
 unit_size = 20.0

+ 51 - 31
player/player.gd

@@ -22,8 +22,16 @@ var velocity = Vector3()
 var aiming = false
 var aiming = false
 var camera_x_rot = 0.0
 var camera_x_rot = 0.0
 
 
+onready var initial_position = transform.origin
 onready var gravity = ProjectSettings.get_setting("physics/3d/default_gravity") * ProjectSettings.get_setting("physics/3d/default_gravity_vector")
 onready var gravity = ProjectSettings.get_setting("physics/3d/default_gravity") * ProjectSettings.get_setting("physics/3d/default_gravity_vector")
 
 
+onready var animation_tree = $AnimationTree
+onready var camera_base = $CameraBase
+onready var camera_animation = $CameraBase/Animation
+onready var camera_rot = $CameraBase/CameraRot
+onready var camera_spring_arm = $CameraBase/CameraRot/SpringArm
+onready var camera = $CameraBase/CameraRot/SpringArm/Camera
+
 func _init():
 func _init():
 	Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
 	Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
 
 
@@ -34,12 +42,16 @@ func _ready():
 	orientation.origin = Vector3()
 	orientation.origin = Vector3()
 
 
 
 
-func rotate_camera(move):
-	$camera_base.rotate_y(-move.x)
-	$camera_base.orthonormalize() # After relative transforms, camera needs to be renormalized.
-	camera_x_rot += move.y
-	camera_x_rot = clamp(camera_x_rot, deg2rad(CAMERA_X_ROT_MIN), deg2rad(CAMERA_X_ROT_MAX))
-	$camera_base/camera_rot.rotation.x = camera_x_rot
+func _process(_delta):
+	# Fade out to black if falling out of the map. -17 is lower than
+	# the lowest valid position on the map (which is a bit under -16).
+	# At 15 units below -17 (so -32), the screen turns fully black.
+	if transform.origin.y < -17:
+		$ColorRect.modulate.a = min((-17 - transform.origin.y) / 15, 1)
+		# If we're below -40, respawn (teleport to the initial position).
+		if transform.origin.y < -40:
+			$ColorRect.modulate.a = 0
+			transform.origin = initial_position
 
 
 
 
 func _physics_process(delta):
 func _physics_process(delta):
@@ -50,10 +62,10 @@ func _physics_process(delta):
 		camera_speed_this_frame *= 0.5
 		camera_speed_this_frame *= 0.5
 	rotate_camera(camera_move * camera_speed_this_frame)
 	rotate_camera(camera_move * camera_speed_this_frame)
 	var motion_target = Vector2(Input.get_action_strength("move_right") - Input.get_action_strength("move_left"), 
 	var motion_target = Vector2(Input.get_action_strength("move_right") - Input.get_action_strength("move_left"), 
-								Input.get_action_strength("move_forward") - Input.get_action_strength("move_back"))
+								Input.get_action_strength("move_back") - Input.get_action_strength("move_forward"))
 	motion = motion.linear_interpolate(motion_target, MOTION_INTERPOLATE_SPEED * delta)
 	motion = motion.linear_interpolate(motion_target, MOTION_INTERPOLATE_SPEED * delta)
 	
 	
-	var camera_basis = $camera_base/camera_rot/Camera.global_transform.basis
+	var camera_basis = camera_rot.global_transform.basis
 	var camera_z = camera_basis.z
 	var camera_z = camera_basis.z
 	var camera_x = camera_basis.x
 	var camera_x = camera_basis.x
 	
 	
@@ -67,9 +79,9 @@ func _physics_process(delta):
 	if aiming != current_aim:
 	if aiming != current_aim:
 			aiming = current_aim
 			aiming = current_aim
 			if (aiming):
 			if (aiming):
-				$camera_base/animation.play("shoot")
+				camera_animation.play("shoot")
 			else:
 			else:
-				$camera_base/animation.play("far")
+				camera_animation.play("far")
 	
 	
 	# Jump/in-air logic.
 	# Jump/in-air logic.
 	airborne_time += delta
 	airborne_time += delta
@@ -83,41 +95,41 @@ func _physics_process(delta):
 	if not on_air and Input.is_action_just_pressed("jump"):
 	if not on_air and Input.is_action_just_pressed("jump"):
 		velocity.y = JUMP_SPEED
 		velocity.y = JUMP_SPEED
 		on_air = true
 		on_air = true
-		$animation_tree["parameters/state/current"] = 2
+		animation_tree["parameters/state/current"] = 2
 		$sfx/jump.play()
 		$sfx/jump.play()
 	
 	
 	if on_air:
 	if on_air:
 		if (velocity.y > 0):
 		if (velocity.y > 0):
-			$animation_tree["parameters/state/current"] = 2
+			animation_tree["parameters/state/current"] = 2
 		else:
 		else:
-			$animation_tree["parameters/state/current"] = 3
+			animation_tree["parameters/state/current"] = 3
 	elif aiming:
 	elif aiming:
 		# Change state to strafe.
 		# Change state to strafe.
-		$animation_tree["parameters/state/current"] = 0
+		animation_tree["parameters/state/current"] = 0
 		
 		
 		# Change aim according to camera rotation.
 		# Change aim according to camera rotation.
 		if camera_x_rot >= 0: # Aim up.
 		if camera_x_rot >= 0: # Aim up.
-			$animation_tree["parameters/aim/add_amount"] = -camera_x_rot / deg2rad(CAMERA_X_ROT_MAX)
+			animation_tree["parameters/aim/add_amount"] = -camera_x_rot / deg2rad(CAMERA_X_ROT_MAX)
 		else: # Aim down.
 		else: # Aim down.
-			$animation_tree["parameters/aim/add_amount"] = camera_x_rot / deg2rad(CAMERA_X_ROT_MIN)
+			animation_tree["parameters/aim/add_amount"] = camera_x_rot / deg2rad(CAMERA_X_ROT_MIN)
 		
 		
 		# Convert orientation to quaternions for interpolating rotation.
 		# Convert orientation to quaternions for interpolating rotation.
 		var q_from = orientation.basis.get_rotation_quat()
 		var q_from = orientation.basis.get_rotation_quat()
-		var q_to = $camera_base.global_transform.basis.get_rotation_quat()
+		var q_to = $CameraBase.global_transform.basis.get_rotation_quat()
 		# Interpolate current rotation with desired one.
 		# Interpolate current rotation with desired one.
 		orientation.basis = Basis(q_from.slerp(q_to, delta * ROTATION_INTERPOLATE_SPEED))
 		orientation.basis = Basis(q_from.slerp(q_to, delta * ROTATION_INTERPOLATE_SPEED))
 		
 		
-		$animation_tree["parameters/strafe/blend_position"] = motion
+		# The animation's forward/backward axis is reversed.
+		animation_tree["parameters/strafe/blend_position"] = Vector2(motion.x, -motion.y)
 		
 		
-		root_motion = $animation_tree.get_root_motion_transform()
+		root_motion = animation_tree.get_root_motion_transform()
 		
 		
 		if Input.is_action_pressed("shoot") and $FireCooldown.time_left == 0:
 		if Input.is_action_pressed("shoot") and $FireCooldown.time_left == 0:
-			var shoot_from = $"Scene Root/Robot_Skeleton/Skeleton/gun_bone/shoot_from".global_transform.origin
-			var cam = $camera_base/camera_rot/Camera
+			var shoot_from = $"Scene Root/Robot_Skeleton/Skeleton/GunBone/ShootFrom".global_transform.origin
 			
 			
-			var ch_pos = $crosshair.rect_position + $crosshair.rect_size * 0.5
-			var ray_from = cam.project_ray_origin(ch_pos)
-			var ray_dir = cam.project_ray_normal(ch_pos)
+			var ch_pos = $Crosshair.rect_position + $Crosshair.rect_size * 0.5
+			var ray_from = camera.project_ray_origin(ch_pos)
+			var ray_dir = camera.project_ray_normal(ch_pos)
 			
 			
 			var shoot_target
 			var shoot_target
 			var col = get_world().direct_space_state.intersect_ray(ray_from, ray_from + ray_dir * 1000, [self])
 			var col = get_world().direct_space_state.intersect_ray(ray_from, ray_from + ray_dir * 1000, [self])
@@ -136,21 +148,21 @@ func _physics_process(delta):
 			$sfx/shoot.play()
 			$sfx/shoot.play()
 	else: # Not in air or aiming, idle.
 	else: # Not in air or aiming, idle.
 		# Convert orientation to quaternions for interpolating rotation.
 		# Convert orientation to quaternions for interpolating rotation.
-		var target = camera_z * motion.y - camera_x * motion.x
+		var target = camera_x * motion.x + camera_z * motion.y
 		if target.length() > 0.001:
 		if target.length() > 0.001:
 			var q_from = orientation.basis.get_rotation_quat()
 			var q_from = orientation.basis.get_rotation_quat()
-			var q_to = Quat(Transform().looking_at(target, Vector3.UP).basis)
-			# Interpolate current rotation with desired one
+			var q_to = Transform().looking_at(target, Vector3.UP).basis.get_rotation_quat()
+			# Interpolate current rotation with desired one.
 			orientation.basis = Basis(q_from.slerp(q_to, delta * ROTATION_INTERPOLATE_SPEED))
 			orientation.basis = Basis(q_from.slerp(q_to, delta * ROTATION_INTERPOLATE_SPEED))
 		
 		
 		# Aim to zero (no aiming while walking).
 		# Aim to zero (no aiming while walking).
-		$animation_tree["parameters/aim/add_amount"] = 0
+		animation_tree["parameters/aim/add_amount"] = 0
 		# Change state to walk.
 		# Change state to walk.
-		$animation_tree["parameters/state/current"] = 1
+		animation_tree["parameters/state/current"] = 1
 		# Blend position for walk speed based on motion.
 		# Blend position for walk speed based on motion.
-		$animation_tree["parameters/walk/blend_position"] = Vector2(motion.length(), 0) 
+		animation_tree["parameters/walk/blend_position"] = Vector2(motion.length(), 0) 
 		
 		
-		root_motion = $animation_tree.get_root_motion_transform()
+		root_motion = animation_tree.get_root_motion_transform()
 	
 	
 	# Apply root motion to orientation.
 	# Apply root motion to orientation.
 	orientation *= root_motion
 	orientation *= root_motion
@@ -173,3 +185,11 @@ func _input(event):
 		if aiming:
 		if aiming:
 			camera_speed_this_frame *= 0.75
 			camera_speed_this_frame *= 0.75
 		rotate_camera(event.relative * camera_speed_this_frame)
 		rotate_camera(event.relative * camera_speed_this_frame)
+
+
+func rotate_camera(move):
+	camera_base.rotate_y(-move.x)
+	camera_base.orthonormalize() # After relative transforms, camera needs to be renormalized.
+	camera_x_rot += move.y
+	camera_x_rot = clamp(camera_x_rot, deg2rad(CAMERA_X_ROT_MIN), deg2rad(CAMERA_X_ROT_MAX))
+	camera_rot.rotation.x = camera_x_rot

+ 71 - 39
player/player.tscn

@@ -126,43 +126,43 @@ y_label = "gun"
 
 
 [sub_resource type="AnimationNodeBlendTree" id=22]
 [sub_resource type="AnimationNodeBlendTree" id=22]
 resource_local_to_scene = true
 resource_local_to_scene = true
-graph_offset = Vector2( -517, 242 )
+graph_offset = Vector2( 1, 85 )
 nodes/aim/node = SubResource( 1 )
 nodes/aim/node = SubResource( 1 )
-nodes/aim/position = Vector2( 340, 120 )
+nodes/aim/position = Vector2( 380, 120 )
 nodes/aimdown/node = SubResource( 2 )
 nodes/aimdown/node = SubResource( 2 )
-nodes/aimdown/position = Vector2( 120, 120 )
+nodes/aimdown/position = Vector2( 120, 60 )
 nodes/aimup/node = SubResource( 3 )
 nodes/aimup/node = SubResource( 3 )
-nodes/aimup/position = Vector2( 140, 420 )
+nodes/aimup/position = Vector2( 140, 380 )
 nodes/eye_blend/node = SubResource( 4 )
 nodes/eye_blend/node = SubResource( 4 )
-nodes/eye_blend/position = Vector2( 560, 120 )
+nodes/eye_blend/position = Vector2( 640, 120 )
 nodes/eyes/node = SubResource( 5 )
 nodes/eyes/node = SubResource( 5 )
-nodes/eyes/position = Vector2( 340, 360 )
+nodes/eyes/position = Vector2( 380, 360 )
 nodes/hardland/node = SubResource( 6 )
 nodes/hardland/node = SubResource( 6 )
-nodes/hardland/position = Vector2( -140, 440 )
+nodes/hardland/position = Vector2( -160, 340 )
 nodes/jumpdown/node = SubResource( 7 )
 nodes/jumpdown/node = SubResource( 7 )
-nodes/jumpdown/position = Vector2( -380, 440 )
+nodes/jumpdown/position = Vector2( -460, 320 )
 nodes/jumpup/node = SubResource( 8 )
 nodes/jumpup/node = SubResource( 8 )
-nodes/jumpup/position = Vector2( -400, 320 )
+nodes/jumpup/position = Vector2( -480, 200 )
 nodes/land/node = SubResource( 9 )
 nodes/land/node = SubResource( 9 )
-nodes/land/position = Vector2( 120, 240 )
-nodes/output/position = Vector2( 760, 120 )
+nodes/land/position = Vector2( 120, 180 )
+nodes/output/position = Vector2( 840, 120 )
 nodes/state/node = SubResource( 10 )
 nodes/state/node = SubResource( 10 )
-nodes/state/position = Vector2( -60, 180 )
+nodes/state/position = Vector2( -120, 120 )
 nodes/strafe/node = SubResource( 16 )
 nodes/strafe/node = SubResource( 16 )
-nodes/strafe/position = Vector2( -340, 120 )
+nodes/strafe/position = Vector2( -400, -120 )
 nodes/walk/node = SubResource( 21 )
 nodes/walk/node = SubResource( 21 )
-nodes/walk/position = Vector2( -340, 220 )
-node_connections = [ "output", 0, "eye_blend", "state", 0, "strafe", "state", 1, "walk", "state", 2, "jumpup", "state", 3, "jumpdown", "eye_blend", 0, "aim", "eye_blend", 1, "eyes", "land", 0, "state", "land", 1, "hardland", "aim", 0, "aimdown", "aim", 1, "land", "aim", 2, "aimup" ]
+nodes/walk/position = Vector2( -400, 40 )
+node_connections = [ "output", 0, "eye_blend", "state", 0, "strafe", "state", 1, "walk", "state", 2, "jumpup", "state", 3, "jumpdown", "land", 0, "state", "land", 1, "hardland", "aim", 0, "aimdown", "aim", 1, "land", "aim", 2, "aimup", "eye_blend", 0, "aim", "eye_blend", 1, "eyes" ]
 
 
 [sub_resource type="CapsuleShape" id=23]
 [sub_resource type="CapsuleShape" id=23]
-radius = 0.490082
-height = 0.560254
+radius = 0.5
+height = 0.6
 
 
 [sub_resource type="RayShape" id=24]
 [sub_resource type="RayShape" id=24]
 
 
 [sub_resource type="Animation" id=25]
 [sub_resource type="Animation" id=25]
 tracks/0/type = "value"
 tracks/0/type = "value"
-tracks/0/path = NodePath("camera_rot/Camera:translation")
+tracks/0/path = NodePath("CameraRot/SpringArm:translation")
 tracks/0/interp = 1
 tracks/0/interp = 1
 tracks/0/loop_wrap = true
 tracks/0/loop_wrap = true
 tracks/0/imported = false
 tracks/0/imported = false
@@ -171,10 +171,10 @@ tracks/0/keys = {
 "times": PoolRealArray( 0, 1 ),
 "times": PoolRealArray( 0, 1 ),
 "transitions": PoolRealArray( 0.287175, 1 ),
 "transitions": PoolRealArray( 0.287175, 1 ),
 "update": 3,
 "update": 3,
-"values": [ Vector3( 0, 0.592719, -2.15676 ), Vector3( 0, 0.592719, -2.15676 ) ]
+"values": [ Vector3( 0, 0, 0 ), Vector3( 0, 0, 0 ) ]
 }
 }
 tracks/1/type = "value"
 tracks/1/type = "value"
-tracks/1/path = NodePath("../crosshair:self_modulate")
+tracks/1/path = NodePath("../Crosshair:self_modulate")
 tracks/1/interp = 1
 tracks/1/interp = 1
 tracks/1/loop_wrap = true
 tracks/1/loop_wrap = true
 tracks/1/imported = false
 tracks/1/imported = false
@@ -188,7 +188,7 @@ tracks/1/keys = {
 
 
 [sub_resource type="Animation" id=26]
 [sub_resource type="Animation" id=26]
 tracks/0/type = "value"
 tracks/0/type = "value"
-tracks/0/path = NodePath("camera_rot/Camera:translation")
+tracks/0/path = NodePath("CameraRot/SpringArm:translation")
 tracks/0/interp = 1
 tracks/0/interp = 1
 tracks/0/loop_wrap = true
 tracks/0/loop_wrap = true
 tracks/0/imported = false
 tracks/0/imported = false
@@ -197,10 +197,10 @@ tracks/0/keys = {
 "times": PoolRealArray( 0, 1 ),
 "times": PoolRealArray( 0, 1 ),
 "transitions": PoolRealArray( 0.233259, 1 ),
 "transitions": PoolRealArray( 0.233259, 1 ),
 "update": 3,
 "update": 3,
-"values": [ Vector3( -0.684193, 0.265504, -1.04126 ), Vector3( -0.684193, 0.265504, -1.04126 ) ]
+"values": [ Vector3( -0.6, -0.3, 1.1 ), Vector3( -0.6, -0.3, 1.1 ) ]
 }
 }
 tracks/1/type = "value"
 tracks/1/type = "value"
-tracks/1/path = NodePath("../crosshair:self_modulate")
+tracks/1/path = NodePath("../Crosshair:self_modulate")
 tracks/1/interp = 1
 tracks/1/interp = 1
 tracks/1/loop_wrap = true
 tracks/1/loop_wrap = true
 tracks/1/imported = false
 tracks/1/imported = false
@@ -215,23 +215,27 @@ tracks/1/keys = {
 [sub_resource type="AudioStreamRandomPitch" id=27]
 [sub_resource type="AudioStreamRandomPitch" id=27]
 audio_stream = ExtResource( 7 )
 audio_stream = ExtResource( 7 )
 
 
-[node name="player" type="KinematicBody"]
-collision_layer = 3
+[node name="Player" type="KinematicBody"]
+collision_layer = 2
+collision_mask = 3
 script = ExtResource( 1 )
 script = ExtResource( 1 )
 
 
 [node name="Scene Root" parent="." instance=ExtResource( 2 )]
 [node name="Scene Root" parent="." instance=ExtResource( 2 )]
 
 
-[node name="gun_bone" type="BoneAttachment" parent="Scene Root/Robot_Skeleton/Skeleton" index="5"]
-transform = Transform( 0.90287, -0.253554, 0.347451, -0.259802, -0.965241, -0.0296011, 0.342916, -0.0635128, -0.93723, -0.207006, 1.36658, 0.538869 )
+[node name="Skeleton" parent="Scene Root/Robot_Skeleton" index="0"]
+bones/46/bound_children = [ NodePath("GunBone") ]
+
+[node name="GunBone" type="BoneAttachment" parent="Scene Root/Robot_Skeleton/Skeleton" index="5"]
+transform = Transform( 0.898624, -0.247907, 0.362217, -0.262223, -0.964987, -0.0102129, 0.352102, -0.0857715, -0.932036, -0.207116, 1.3624, 0.547539 )
 bone_name = "hand.R"
 bone_name = "hand.R"
 
 
-[node name="shoot_from" type="Position3D" parent="Scene Root/Robot_Skeleton/Skeleton/gun_bone"]
+[node name="ShootFrom" type="Position3D" parent="Scene Root/Robot_Skeleton/Skeleton/GunBone"]
 transform = Transform( 0.999919, 0.0106283, -0.00705317, -0.0105956, 0.99993, 0.00505793, 0.00710796, -0.0049828, 0.999962, 0.0100024, -0.00491095, -0.40371 )
 transform = Transform( 0.999919, 0.0106283, -0.00705317, -0.0105956, 0.99993, 0.00505793, 0.00710796, -0.0049828, 0.999962, 0.0100024, -0.00491095, -0.40371 )
 
 
 [node name="RootMotionView" type="RootMotionView" parent="."]
 [node name="RootMotionView" type="RootMotionView" parent="."]
 animation_path = NodePath("../AnimationTree")
 animation_path = NodePath("../AnimationTree")
 
 
-[node name="animation_tree" type="AnimationTree" parent="."]
+[node name="AnimationTree" type="AnimationTree" parent="."]
 tree_root = SubResource( 22 )
 tree_root = SubResource( 22 )
 anim_player = NodePath("../Scene Root/AnimationPlayer")
 anim_player = NodePath("../Scene Root/AnimationPlayer")
 active = true
 active = true
@@ -244,29 +248,54 @@ parameters/state/current = 0
 parameters/strafe/blend_position = Vector2( 0, 0 )
 parameters/strafe/blend_position = Vector2( 0, 0 )
 parameters/walk/blend_position = Vector2( 0, 0 )
 parameters/walk/blend_position = Vector2( 0, 0 )
 
 
-[node name="CollisionShape" type="CollisionShape" parent="."]
-transform = Transform( 1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 1.03615, 0 )
+[node name="CapsuleShape" type="CollisionShape" parent="."]
+transform = Transform( 1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 1, 0 )
 shape = SubResource( 23 )
 shape = SubResource( 23 )
 
 
-[node name="CollisionShape2" type="CollisionShape" parent="."]
+[node name="RayShape" type="CollisionShape" parent="."]
 transform = Transform( 1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 1.00357, 0 )
 transform = Transform( 1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 1.00357, 0 )
 shape = SubResource( 24 )
 shape = SubResource( 24 )
 
 
-[node name="camera_base" type="Spatial" parent="."]
-transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.85456, 0 )
+[node name="Spatial" type="Position3D" parent="."]
+transform = Transform( -1, 1.18511e-07, -3.03525e-07, 0, 0.931513, 0.363707, 3.25841e-07, 0.363707, -0.931513, 0, 2.44728, -2.15676 )
+
+[node name="CameraBase" type="Spatial" parent="."]
+transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.6, 0 )
+__meta__ = {
+"_editor_description_": "Handles Y rotation (yaw)."
+}
+
+[node name="CameraRot" type="Spatial" parent="CameraBase"]
+__meta__ = {
+"_editor_description_": "Handles X rotation (pitch)."
+}
 
 
-[node name="camera_rot" type="Spatial" parent="camera_base"]
+[node name="SpringArm" type="SpringArm" parent="CameraBase/CameraRot"]
+transform = Transform( -1, -1.11444e-07, 3.06191e-07, 0, 0.939693, 0.34202, -3.25841e-07, 0.34202, -0.939693, 0, 0, 0 )
+spring_length = 2.4
 
 
-[node name="Camera" type="Camera" parent="camera_base/camera_rot"]
-transform = Transform( -1, 0, -8.74228e-08, -3.17959e-08, 0.931515, 0.363703, 8.14356e-08, 0.363703, -0.931515, 0, 0.592719, -2.15676 )
+[node name="Camera" type="Camera" parent="CameraBase/CameraRot/SpringArm"]
+transform = Transform( 1, 1.42109e-14, -2.84217e-14, 0, 1, 0, 0, 0, 1, 0, 0, 0 )
 current = true
 current = true
 far = 300.0
 far = 300.0
+__meta__ = {
+"_editor_description_": "Translated when aiming."
+}
 
 
-[node name="animation" type="AnimationPlayer" parent="camera_base"]
+[node name="Animation" type="AnimationPlayer" parent="CameraBase"]
 anims/far = SubResource( 25 )
 anims/far = SubResource( 25 )
 anims/shoot = SubResource( 26 )
 anims/shoot = SubResource( 26 )
 
 
-[node name="crosshair" type="TextureRect" parent="."]
+[node name="ColorRect" type="ColorRect" parent="."]
+modulate = Color( 1, 1, 1, 0 )
+anchor_right = 1.0
+anchor_bottom = 1.0
+color = Color( 0, 0, 0, 1 )
+__meta__ = {
+"_edit_use_anchors_": false
+}
+
+[node name="Crosshair" type="TextureRect" parent="."]
 self_modulate = Color( 1, 1, 1, 0 )
 self_modulate = Color( 1, 1, 1, 0 )
 anchor_left = 0.5
 anchor_left = 0.5
 anchor_top = 0.5
 anchor_top = 0.5
@@ -277,6 +306,9 @@ margin_top = -23.8394
 margin_right = 14.6654
 margin_right = 14.6654
 margin_bottom = 8.16064
 margin_bottom = 8.16064
 texture = ExtResource( 3 )
 texture = ExtResource( 3 )
+__meta__ = {
+"_edit_use_anchors_": false
+}
 
 
 [node name="sfx" type="Node" parent="."]
 [node name="sfx" type="Node" parent="."]
 
 

+ 6 - 1
project.godot

@@ -194,9 +194,14 @@ toggle_fullscreen={
  ]
  ]
 }
 }
 
 
+[layer_names]
+
+3d_physics/layer_1="Level"
+3d_physics/layer_2="Player"
+
 [physics]
 [physics]
 
 
-3d/physics_engine="GodotPhysics"
+3d/physics_engine="Bullet"
 
 
 [rendering]
 [rendering]