Explorar el Código

[3DP] Update to Godot 3.1.2

Conform to style guide, add WASD movement, add controller support
Aaron Franke hace 5 años
padre
commit
33494c4592

+ 2 - 3
3d/platformer/bullet.gd

@@ -1,5 +1,4 @@
-
 extends RigidBody
 
-# Member variables
-var disabled = false
+#warning-ignore:unused_class_variable
+var enabled = true

+ 11 - 14
3d/platformer/bullet.tscn

@@ -25,7 +25,7 @@ surfaces/0 = {
 "vertex_count": 34
 }
 
-[sub_resource type="SpatialMaterial" id=6]
+[sub_resource type="SpatialMaterial" id=3]
 albedo_color = Color( 0.7, 0.7, 0.7, 1 )
 metallic = 0.1
 roughness = 0.0
@@ -35,8 +35,7 @@ emission_energy = 3.71
 emission_operator = 0
 emission_on_uv2 = false
 
-[sub_resource type="Animation" id=3]
-resource_name = "life"
+[sub_resource type="Animation" id=4]
 length = 2.0
 tracks/0/type = "value"
 tracks/0/path = NodePath("Sphere:visible")
@@ -63,7 +62,7 @@ tracks/1/keys = {
 "values": [ true, false ]
 }
 tracks/2/type = "method"
-tracks/2/path = NodePath(".:")
+tracks/2/path = NodePath(".")
 tracks/2/interp = 1
 tracks/2/loop_wrap = true
 tracks/2/imported = false
@@ -77,19 +76,19 @@ tracks/2/keys = {
 } ]
 }
 
-[sub_resource type="Gradient" id=8]
+[sub_resource type="Gradient" id=5]
 colors = PoolColorArray( 1, 1, 1, 1, 1, 1, 1, 0 )
 
-[sub_resource type="GradientTexture" id=9]
-gradient = SubResource( 8 )
+[sub_resource type="GradientTexture" id=6]
+gradient = SubResource( 5 )
 
 [sub_resource type="ParticlesMaterial" id=7]
 spread = 0.0
 gravity = Vector3( 0, 0, 0 )
 scale = 0.3
-color_ramp = SubResource( 9 )
+color_ramp = SubResource( 6 )
 
-[sub_resource type="SphereShape" id=5]
+[sub_resource type="SphereShape" id=8]
 radius = 0.27
 
 [node name="Bullet" type="RigidBody"]
@@ -102,13 +101,11 @@ __meta__ = {
 [node name="Sphere" type="MeshInstance" parent="."]
 transform = Transform( 0.24972, 0, 0, 0, 0.24972, 0, 0, 0, 0.24972, 0.00159812, 0.0110106, 0.0045104 )
 mesh = SubResource( 2 )
-skeleton = NodePath("..:")
-material/0 = SubResource( 6 )
+material/0 = SubResource( 3 )
 
 [node name="AnimationPlayer" type="AnimationPlayer" parent="."]
-root_node = NodePath("..:")
 autoplay = "life"
-anims/life = SubResource( 3 )
+anims/life = SubResource( 4 )
 
 [node name="Particles" type="Particles" parent="."]
 amount = 16
@@ -120,4 +117,4 @@ process_material = SubResource( 7 )
 draw_pass_1 = SubResource( 2 )
 
 [node name="CollisionShape" type="CollisionShape" parent="."]
-shape = SubResource( 5 )
+shape = SubResource( 8 )

+ 0 - 3
3d/platformer/coin.gd

@@ -1,10 +1,7 @@
-
 extends Area
 
-# Member variables
 var taken = false
 
-
 func _on_coin_body_enter(body):
 	if not taken and body is preload("res://player.gd"):
 		get_node("Animation").play("take")

+ 13 - 14
3d/platformer/coin.tscn

@@ -85,23 +85,24 @@ tracks/2/keys = {
 "values": [ true ]
 }
 
-[sub_resource type="SphereShape" id=7]
+[sub_resource type="SphereShape" id=5]
 radius = 0.312546
 
-[sub_resource type="Gradient" id=8]
+[sub_resource type="Gradient" id=6]
 colors = PoolColorArray( 1, 1, 1, 1, 1, 1, 1, 0 )
 
-[sub_resource type="GradientTexture" id=9]
-gradient = SubResource( 8 )
+[sub_resource type="GradientTexture" id=7]
+gradient = SubResource( 6 )
 
-[sub_resource type="ParticlesMaterial" id=10]
+[sub_resource type="ParticlesMaterial" id=8]
 emission_shape = 2
 emission_box_extents = Vector3( 0.3, 0.3, 0.3 )
 initial_velocity = 5.51
+angular_velocity = 4.27461e-05
 scale = 0.1
-color_ramp = SubResource( 9 )
+color_ramp = SubResource( 7 )
 
-[sub_resource type="SpatialMaterial" id=11]
+[sub_resource type="SpatialMaterial" id=9]
 flags_transparent = true
 flags_unshaded = true
 vertex_color_use_as_albedo = true
@@ -114,8 +115,8 @@ particles_anim_loop = false
 albedo_color = Color( 1, 1, 0.759137, 1 )
 albedo_texture = ExtResource( 3 )
 
-[sub_resource type="QuadMesh" id=12]
-material = SubResource( 11 )
+[sub_resource type="QuadMesh" id=10]
+material = SubResource( 9 )
 
 [node name="Coin" type="Area"]
 input_ray_pickable = false
@@ -128,18 +129,16 @@ __meta__ = {
 transform = Transform( 0.2, 0, 0, 0, -3.25841e-08, 0.2, 0, -0.2, -3.25841e-08, 0.00550658, 0.532125, 0.000651598 )
 layers = 2
 mesh = SubResource( 2 )
-skeleton = NodePath("..:")
 material/0 = null
 
 [node name="Animation" type="AnimationPlayer" parent="."]
-root_node = NodePath("..:")
 autoplay = "spin"
 anims/spin = SubResource( 3 )
 anims/take = SubResource( 4 )
 
 [node name="CollisionShape" type="CollisionShape" parent="."]
 transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.00894194, 0.575859, 0.0193955 )
-shape = SubResource( 7 )
+shape = SubResource( 5 )
 
 [node name="VisibilityEnabler" type="VisibilityEnabler" parent="."]
 transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.0321827, 0.57887, 0.0268312 )
@@ -155,6 +154,6 @@ emitting = false
 one_shot = true
 explosiveness = 1.0
 visibility_aabb = AABB( -4.12919, -4, -4, 8.25837, 8, 8 )
-process_material = SubResource( 10 )
-draw_pass_1 = SubResource( 12 )
+process_material = SubResource( 8 )
+draw_pass_1 = SubResource( 10 )
 [connection signal="body_entered" from="." to="." method="_on_coin_body_enter"]

+ 12 - 14
3d/platformer/enemy.gd

@@ -1,7 +1,5 @@
-
 extends RigidBody
 
-# Member variables
 const STATE_WALKING = 0
 const STATE_DYING = 1
 
@@ -14,15 +12,17 @@ var rot_speed = 1
 
 var dying = false
 
+onready var gravity = ProjectSettings.get_setting("physics/3d/default_gravity") * ProjectSettings.get_setting("physics/3d/default_gravity_vector")
 
 func _integrate_forces(state):
 	var delta = state.get_step()
 	var lv = state.get_linear_velocity()
 	var g = state.get_total_gravity()
-	# get_total_gravity returns zero for the first few frames, leading to errors
-	if g == Vector3.ZERO: g = Vector3 (0, -9.8, 0)
+	# get_total_gravity returns zero for the first few frames, leading to errors.
+	if g == Vector3.ZERO:
+		g = gravity
 
-	lv += g * delta # Apply gravity
+	lv += g * delta # Apply gravity.
 	var up = -g.normalized()
 	
 	if dying:
@@ -34,22 +34,20 @@ func _integrate_forces(state):
 		var dp = state.get_contact_local_normal(i)
 		
 		if cc:
-			if cc is preload("res://bullet.gd") and not cc.disabled:
+			if cc is preload("res://bullet.gd") and cc.enabled:
 				set_mode(MODE_RIGID)
 				dying = true
-				#lv = s.get_contact_local_normal(i)*400
 				state.set_angular_velocity(-dp.cross(up).normalized() * 33.0)
 				get_node("AnimationPlayer").play("impact")
 				get_node("AnimationPlayer").queue("explode")
-				set_friction(1)
-				cc.disabled = true
-				get_node("sound_hit").play()
+				cc.enabled = false
+				get_node("SoundHit").play()
 				return
 	
-	var col_floor = get_node("Armature/ray_floor").is_colliding()
-	var col_wall = get_node("Armature/ray_wall").is_colliding()
+	var col_floor = get_node("Armature/RayFloor").is_colliding()
+	var col_wall = get_node("Armature/RayWall").is_colliding()
 	
-	var advance = not col_wall and col_floor
+	var advance = col_floor and not col_wall
 	
 	var dir = get_node("Armature").get_transform().basis[2].normalized()
 	var deaccel_dir = dir
@@ -60,7 +58,7 @@ func _integrate_forces(state):
 		deaccel_dir = dir.cross(g).normalized()
 	else:
 		if prev_advance:
-			rot_dir = 1 # randf()*2.0 - 1.0
+			rot_dir = 1
 		
 		dir = Basis(up, rot_dir * rot_speed * delta).xform(dir)
 		get_node("Armature").set_transform(Transform().looking_at(-dir, up))

+ 47 - 50
3d/platformer/enemy.tscn

@@ -6,7 +6,7 @@
 [ext_resource path="res://sound_explode.wav" type="AudioStream" id=4]
 [ext_resource path="res://shine.png" type="Texture" id=5]
 
-[sub_resource type="PhysicsMaterial" id=22]
+[sub_resource type="PhysicsMaterial" id=1]
 friction = 0.0
 
 [sub_resource type="SpatialMaterial" id=2]
@@ -67,7 +67,7 @@ surfaces/2 = {
 "vertex_count": 28
 }
 
-[sub_resource type="Animation" id=7]
+[sub_resource type="Animation" id=6]
 length = 2.5
 tracks/0/type = "transform"
 tracks/0/path = NodePath("Armature/Skeleton:r-backleg.001")
@@ -147,11 +147,11 @@ tracks/10/imported = false
 tracks/10/enabled = true
 tracks/10/keys = PoolRealArray( 0, 1, 0, 5.96046e-08, 0, 0, 0, 0, 1, 1, 1, 1 )
 
-[sub_resource type="Animation" id=10]
+[sub_resource type="Animation" id=7]
 resource_name = "explode"
 length = 3.0
 tracks/0/type = "value"
-tracks/0/path = NodePath("explosion:emitting")
+tracks/0/path = NodePath("Explosion:emitting")
 tracks/0/interp = 1
 tracks/0/loop_wrap = true
 tracks/0/imported = false
@@ -175,7 +175,7 @@ tracks/1/keys = {
 "values": [ true, false ]
 }
 tracks/2/type = "method"
-tracks/2/path = NodePath(".:")
+tracks/2/path = NodePath(".")
 tracks/2/interp = 1
 tracks/2/loop_wrap = true
 tracks/2/imported = false
@@ -189,7 +189,7 @@ tracks/2/keys = {
 } ]
 }
 tracks/3/type = "value"
-tracks/3/path = NodePath("sound_explode:playing")
+tracks/3/path = NodePath("SoundExplode:playing")
 tracks/3/interp = 1
 tracks/3/loop_wrap = true
 tracks/3/imported = false
@@ -201,7 +201,7 @@ tracks/3/keys = {
 "values": [ true ]
 }
 tracks/4/type = "value"
-tracks/4/path = NodePath("sound_walk_loop:playing")
+tracks/4/path = NodePath("SoundWalkLoop:playing")
 tracks/4/interp = 1
 tracks/4/loop_wrap = true
 tracks/4/imported = false
@@ -213,8 +213,7 @@ tracks/4/keys = {
 "values": [ false ]
 }
 
-[sub_resource type="Animation" id=6]
-resource_name = "idle"
+[sub_resource type="Animation" id=8]
 length = 2.5
 loop = true
 tracks/0/type = "transform"
@@ -375,7 +374,7 @@ tracks/10/imported = false
 tracks/10/enabled = true
 tracks/10/keys = PoolRealArray( 0, 1, 0, 5.96046e-08, 0, 0, 0, 0, 1, 1, 1, 1, 2.5, 1, 0, 5.96046e-08, 0, 0, 0, 0, 1, 1, 1, 1 )
 
-[sub_resource type="Animation" id=8]
+[sub_resource type="Animation" id=10]
 length = 1.66667
 loop = true
 tracks/0/type = "transform"
@@ -456,35 +455,35 @@ tracks/10/imported = false
 tracks/10/enabled = true
 tracks/10/keys = PoolRealArray( 0, 1, 0, -0.149993, 0, 0, 0, 0, 1, 1, 1, 1, 0.05, 1, 0, -0.12914, 0, 0, 0, 0, 1, 1, 1, 1, 0.15, 1, 0, -0.0283493, 0, 0, 0, 0, 1, 1, 1, 1, 0.2, 1, 0, -0.00266618, 0, 0, 0, 0, 1, 1, 1, 1, 0.25, 1, 0, -0.0155987, 0.0483675, 0, 0, 0, 1, 1, 1, 1, 0.3, 1, 0, -0.0777871, 0.182986, 0, 0, 3.55271e-15, 1, 1, 1, 1, 0.35, 1, 0, -0.171135, 0.269949, 0, 0, 0, 1, 1, 1, 1, 0.4, 1, 0, -0.273424, 0.297207, 0, 0, 0, 1, 1, 1, 1, 0.45, 1, 0, -0.3, 0.278664, 0, 0, 0, 1, 1, 1, 1, 0.5, 1, 0, -0.3, 0.198231, 0, 0, 0, 1, 1, 1, 1, 0.55, 1, 0, -0.3, 0.0867803, 0, 0, 0, 1, 1, 1, 1, 0.6, 1, 0, -0.3, 0.0160092, 0, 0, 0, 1, 1, 1, 1, 0.65, 1, 0, -0.296009, -5.96046e-08, 0, 0, 0, 1, 1, 1, 1, 0.7, 1, 0, -0.277333, -5.96046e-08, 0, 0, 0, 1, 1, 1, 1, 0.75, 1, 0, -0.240782, 0, 0, 0, 0, 1, 1, 1, 1, 0.95, 1, 0, -0.0331749, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, -0.00665081, 0, 0, 0, 0, 1, 1, 1, 1, 1.05, 1, 0, -0.00311971, 0.0096736, 0, 0, 0, 1, 1, 1, 1, 1.1, 1, 0, -0.0353009, 0.0950568, 0, 0, 0, 1, 1, 1, 1, 1.15, 1, 0, -0.103653, 0.218778, 0, 0, 0, 1, 1, 1, 1, 1.2, 1, 0, -0.212752, 0.285328, 0, 0, 0, 1, 1, 1, 1, 1.25, 1, 0, -0.3, 0.3, 0, 0, 0, 1, 1, 1, 1, 1.3, 1, 0, -0.3, 0.258311, 0, 0, 0, 1, 1, 1, 1, 1.4, 1, 0, -0.3, 0.0567318, 0, 0, 0, 1, 1, 1, 1, 1.45, 1, 0, -0.3, 0.00533658, 0, 0, 0, 1, 1, 1, 1, 1.5, 1, 0, -0.286666, -5.96046e-08, 0, 0, 0, 1, 1, 1, 1, 1.6, 1, 0, -0.185874, 0, 0, 0, 0, 1, 1, 1, 1, 1.65, 1, 0, -0.15533, 0, 0, 0, 0, 1, 1, 1, 1, 1.7, 1, 0, -0.149993, 0, 0, 0, 0, 1, 1, 1, 1, 2.5, 1, 0, -0.149993, 0, 0, 0, 0, 1, 1, 1, 1 )
 
-[sub_resource type="SphereShape" id=13]
+[sub_resource type="SphereShape" id=11]
 radius = 0.68
 
-[sub_resource type="SphereShape" id=1]
+[sub_resource type="SphereShape" id=12]
 radius = 0.4
 
-[sub_resource type="BoxShape" id=16]
+[sub_resource type="BoxShape" id=13]
 extents = Vector3( 0.57253, 0.388409, 0.560511 )
 
-[sub_resource type="AudioStreamRandomPitch" id=15]
+[sub_resource type="AudioStreamRandomPitch" id=14]
 audio_stream = ExtResource( 2 )
 
-[sub_resource type="Curve" id=17]
+[sub_resource type="Curve" id=15]
 max_value = 3.0
 _data = [ Vector2( 0, 1 ), 0.0, 0.0, 0, 0, Vector2( 0.0349232, 2.1123 ), 0.0, 0.0, 0, 0, Vector2( 0.151192, 0.823242 ), 0.0, 0.0, 0, 0, Vector2( 1, 0 ), 0.0, 0.0, 0, 0 ]
 
-[sub_resource type="CurveTexture" id=18]
-curve = SubResource( 17 )
+[sub_resource type="CurveTexture" id=16]
+curve = SubResource( 15 )
 
-[sub_resource type="ParticlesMaterial" id=19]
+[sub_resource type="ParticlesMaterial" id=17]
 emission_shape = 1
 emission_sphere_radius = 1.0
 gravity = Vector3( 0, 0, 0 )
 initial_velocity = 0.15
 angular_velocity = 351.05
 angular_velocity_random = 1.0
-scale_curve = SubResource( 18 )
+scale_curve = SubResource( 16 )
 
-[sub_resource type="SpatialMaterial" id=20]
+[sub_resource type="SpatialMaterial" id=18]
 flags_transparent = true
 flags_unshaded = true
 params_blend_mode = 1
@@ -494,12 +493,12 @@ particles_anim_v_frames = 1
 particles_anim_loop = false
 albedo_texture = ExtResource( 5 )
 
-[sub_resource type="QuadMesh" id=21]
-material = SubResource( 20 )
+[sub_resource type="QuadMesh" id=19]
+material = SubResource( 18 )
 
-[node name="enemy" type="RigidBody"]
+[node name="Enemy" type="RigidBody"]
 mode = 2
-physics_material_override = SubResource( 22 )
+physics_material_override = SubResource( 1 )
 custom_integrator = true
 contacts_reported = 5
 contact_monitor = true
@@ -570,75 +569,73 @@ bones/10/bound_children = [  ]
 [node name="Sphere" type="MeshInstance" parent="Armature/Skeleton"]
 layers = 2
 mesh = SubResource( 5 )
-skeleton = NodePath("..:")
 material/0 = null
 material/1 = null
 material/2 = null
 
-[node name="ray_floor" type="RayCast" parent="Armature"]
+[node name="RayFloor" type="RayCast" parent="Armature"]
 transform = Transform( 1, 0, 0, 0, 0.576528, 0.817077, 0, -0.817077, 0.576528, 0, 0.643772, 0.803052 )
 enabled = true
 cast_to = Vector3( 0, -2, 0 )
 
-[node name="ray_wall" type="RayCast" parent="Armature"]
+[node name="RayWall" type="RayCast" parent="Armature"]
 transform = Transform( 1, 0, 0, 0, -0.0374391, 0.999299, 0, -0.999299, -0.0374391, 0, 0.643772, 0.310413 )
 enabled = true
 cast_to = Vector3( 0, -3, 0 )
 
 [node name="AnimationPlayer" type="AnimationPlayer" parent="."]
-root_node = NodePath("..:")
 autoplay = "walk-cycle"
 playback_default_blend_time = 0.5
-anims/default = SubResource( 7 )
-anims/explode = SubResource( 10 )
-anims/idle = SubResource( 6 )
+anims/default = SubResource( 6 )
+anims/explode = SubResource( 7 )
+anims/idle = SubResource( 8 )
 anims/impact = SubResource( 9 )
-anims/walk-cycle = SubResource( 8 )
+anims/walk-cycle = SubResource( 10 )
 
-[node name="sphere" type="CollisionShape" parent="."]
+[node name="Sphere1" type="CollisionShape" parent="."]
 transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.74185, 0.267137 )
-shape = SubResource( 13 )
+shape = SubResource( 11 )
 
-[node name="sphere 2" type="CollisionShape" parent="."]
+[node name="Sphere2" type="CollisionShape" parent="."]
 transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.491839, 0.74185, 0.852485 )
-shape = SubResource( 1 )
+shape = SubResource( 12 )
 
-[node name="sphere 3" type="CollisionShape" parent="."]
+[node name="Sphere3" type="CollisionShape" parent="."]
 transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.652943, 0.74185, 0.852485 )
-shape = SubResource( 1 )
+shape = SubResource( 12 )
 
-[node name="sphere 4" type="CollisionShape" parent="."]
+[node name="Sphere4" type="CollisionShape" parent="."]
 transform = Transform( 0.617236, 0, 0.786778, 0, 1, 0, -0.786778, 0, 0.617236, -0.0445105, 1.04515, 0.0531231 )
-shape = SubResource( 16 )
+shape = SubResource( 13 )
 
-[node name="box" type="CollisionShape" parent="."]
+[node name="Box" type="CollisionShape" parent="."]
 transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.678859, 0.74185, -0.335599 )
-shape = SubResource( 1 )
+shape = SubResource( 12 )
 
-[node name="sound" type="Spatial" parent="."]
+[node name="Sound" type="Spatial" parent="."]
 
-[node name="sound_walk_loop" type="AudioStreamPlayer3D" parent="."]
-stream = SubResource( 15 )
+[node name="SoundWalkLoop" type="AudioStreamPlayer3D" parent="."]
+stream = SubResource( 14 )
 unit_db = 12.0
 autoplay = true
 max_distance = 30.0
 out_of_range_mode = 1
 doppler_tracking = 1
 
-[node name="sound_hit" type="AudioStreamPlayer3D" parent="."]
+[node name="SoundHit" type="AudioStreamPlayer3D" parent="."]
 stream = ExtResource( 3 )
 unit_db = 6.0
 doppler_tracking = 1
 
-[node name="sound_explode" type="AudioStreamPlayer3D" parent="."]
+[node name="SoundExplode" type="AudioStreamPlayer3D" parent="."]
 stream = ExtResource( 4 )
 unit_db = 18.0
 doppler_tracking = 1
 
-[node name="explosion" type="Particles" parent="."]
+[node name="Explosion" type="Particles" parent="."]
 emitting = false
 lifetime = 0.5
 one_shot = true
 explosiveness = 1.0
-process_material = SubResource( 19 )
-draw_pass_1 = SubResource( 21 )
+process_material = SubResource( 17 )
+draw_pass_1 = SubResource( 19 )

+ 32 - 36
3d/platformer/follow_camera.gd

@@ -1,80 +1,76 @@
-
 extends Camera
 
-# Member variables
-var collision_exception = []
 export var min_distance = 0.5
 export var max_distance = 3.5
 export var angle_v_adjust = 0.0
 export var autoturn_ray_aperture = 25
 export var autoturn_speed = 50
+
+var collision_exception = []
 var max_height = 2.0
 var min_height = 0
 
+func _ready():
+	# Find collision exceptions for ray.
+	var node = self
+	while node:
+		if node is RigidBody:
+			collision_exception.append(node.get_rid())
+			break
+		else:
+			node = node.get_parent()
+	set_physics_process(true)
+	# This detaches the camera transform from the parent spatial node.
+	set_as_toplevel(true)
+
+
 func _physics_process(dt):
 	var target = get_parent().get_global_transform().origin
 	var pos = get_global_transform().origin
-	var up = Vector3(0, 1, 0)
 
 	var delta = pos - target
 
-	# Regular delta follow
+	# Regular delta follow.
 
-	# Check ranges
-	if  delta.length() < min_distance:
+	# Check ranges.
+	if delta.length() < min_distance:
 		delta = delta.normalized() * min_distance
 	elif  delta.length() > max_distance:
 		delta = delta.normalized() * max_distance
 
-	# Check upper and lower height
+	# Check upper and lower height.
 	if delta.y > max_height:
 		delta.y = max_height
 	if delta.y < min_height:
 		delta.y = min_height
 
-	# Check autoturn
+	# Check autoturn.
 	var ds = PhysicsServer.space_get_direct_state(get_world().get_space())
 
-	var col_left = ds.intersect_ray(target, target + Basis(up, deg2rad(autoturn_ray_aperture)).xform(delta), collision_exception)
+	var col_left = ds.intersect_ray(target, target + Basis(Vector3.UP, deg2rad(autoturn_ray_aperture)).xform(delta), collision_exception)
 	var col = ds.intersect_ray(target, target + delta, collision_exception)
-	var col_right = ds.intersect_ray(target, target + Basis(up, deg2rad(-autoturn_ray_aperture)).xform(delta), collision_exception)
+	var col_right = ds.intersect_ray(target, target + Basis(Vector3.UP, deg2rad(-autoturn_ray_aperture)).xform(delta), collision_exception)
 
 	if !col.empty():
-		# If main ray was occluded, get camera closer, this is the worst case scenario
+		# If main ray was occluded, get camera closer, this is the worst case scenario.
 		delta = col.position - target
 	elif !col_left.empty() and col_right.empty():
-		# If only left ray is occluded, turn the camera around to the right
-		delta = Basis(up, deg2rad(-dt * autoturn_speed)).xform(delta)
+		# If only left ray is occluded, turn the camera around to the right.
+		delta = Basis(Vector3.UP, deg2rad(-dt * autoturn_speed)).xform(delta)
 	elif col_left.empty() and !col_right.empty():
-		# If only right ray is occluded, turn the camera around to the left
-		delta = Basis(up, deg2rad(dt  *autoturn_speed)).xform(delta)
-	else:
-		# Do nothing otherwise, left and right are occluded but center is not, so do not autoturn
-		pass
+		# If only right ray is occluded, turn the camera around to the left.
+		delta = Basis(Vector3.UP, deg2rad(dt  *autoturn_speed)).xform(delta)
+	# Do nothing otherwise, left and right are occluded but center is not, so do not autoturn.
 
-	# Apply lookat
+	# Apply lookat.
 	if delta == Vector3():
 		delta = (pos - target).normalized() * 0.0001
 
 	pos = target + delta
 
-	look_at_from_position(pos, target, up)
+	look_at_from_position(pos, target, Vector3.UP)
 
-	# Turn a little up or down
+	# Turn a little up or down.
 	var t = get_transform()
 	t.basis = Basis(t.basis[0], deg2rad(angle_v_adjust)) * t.basis
 	set_transform(t)
-
-
-func _ready():
-	# Find collision exceptions for ray
-	var node = self
-	while node:
-		if node is RigidBody:
-			collision_exception.append(node.get_rid())
-			break
-		else:
-			node = node.get_parent()
-	set_physics_process(true)
-	# This detaches the camera transform from the parent spatial node
-	set_as_toplevel(true)

+ 59 - 82
3d/platformer/player.gd

@@ -1,110 +1,68 @@
-
 extends KinematicBody
 
-# Member variables
 const ANIM_FLOOR = 0
 const ANIM_AIR_UP = 1
 const ANIM_AIR_DOWN = 2
 
 const SHOOT_TIME = 1.5
 const SHOOT_SCALE = 2
-
 const CHAR_SCALE = Vector3(0.3, 0.3, 0.3)
+const TURN_SPEED = 40
 
-var facing_dir = Vector3(1, 0, 0)
+var facing_dir = Vector3.RIGHT
 var movement_dir = Vector3()
+var linear_velocity = Vector3()
 
 var jumping = false
 
-var turn_speed = 40
-var keep_jump_inertia = true
 var air_idle_deaccel = false
 var accel = 19.0
 var deaccel = 14.0
 var sharp_turn_threshold = 140
-
 var max_speed = 3.1
 
 var prev_shoot = false
-
-var linear_velocity=Vector3()
-
 var shoot_blend = 0
 
-func adjust_facing(p_facing, p_target, p_step, p_adjust_rate, current_gn):
-	var n = p_target # Normal
-	var t = n.cross(current_gn).normalized()
-	 
-	var x = n.dot(p_facing)
-	var y = t.dot(p_facing)
-	
-	var ang = atan2(y,x)
-	
-	if abs(ang) < 0.001: # Too small
-		return p_facing
-	
-	var s = sign(ang)
-	ang = ang * s
-	var turn = ang * p_adjust_rate * p_step
-	var a
-	if ang < turn:
-		a = ang
-	else:
-		a = turn
-	ang = (ang - a) * s
-	
-	return (n * cos(ang) + t * sin(ang)) * p_facing.length()
+onready var gravity = ProjectSettings.get_setting("physics/3d/default_gravity") * ProjectSettings.get_setting("physics/3d/default_gravity_vector")
+
+func _ready():
+	get_node("AnimationTreePlayer").set_active(true)
 
 
 func _physics_process(delta):
-	
-	var lv = linear_velocity
-	var g = Vector3(0, -9.8, 0)
-
-#	var d = 1.0 - delta*state.get_total_density()
-#	if (d < 0):
-#		d = 0
-	lv += g * delta # Apply gravity
+	linear_velocity += gravity * delta
 	
 	var anim = ANIM_FLOOR
 	
-	var up = -g.normalized() # (up is against gravity)
-	var vv = up.dot(lv) # Vertical velocity
-	var hv = lv - up * vv # Horizontal velocity
-	
-	var hdir = hv.normalized() # Horizontal direction
-	var hspeed = hv.length() # Horizontal speed
+	var vv = linear_velocity.y # Vertical velocity.
+	var hv = Vector3(linear_velocity.x, 0, linear_velocity.z) # Horizontal velocity.
 	
-	var dir = Vector3() # Where does the player intend to walk to
-	var cam_xform = get_node("Target/Camera").get_global_transform()
+	var hdir = hv.normalized() # Horizontal direction.
+	var hspeed = hv.length() # Horizontal speed.
 	
-	if Input.is_action_pressed("move_forward"):
-		dir += -cam_xform.basis[2]
-	if Input.is_action_pressed("move_backwards"):
-		dir += cam_xform.basis[2]
-	if Input.is_action_pressed("move_left"):
-		dir += -cam_xform.basis[0]
-	if Input.is_action_pressed("move_right"):
-		dir += cam_xform.basis[0]
+	# Player input
+	var cam_basis = get_node("Target/Camera").get_global_transform().basis
+	var dir = Vector3() # Where does the player intend to walk to.
+	dir = Input.get_action_strength("move_right") * cam_basis[0]
+	dir -= Input.get_action_strength("move_left") * cam_basis[0]
+	dir += Input.get_action_strength("move_backwards") * cam_basis[2]
+	dir -= Input.get_action_strength("move_forward") * cam_basis[2]
+	dir.y = 0
+	dir = dir.normalized()
 	
 	var jump_attempt = Input.is_action_pressed("jump")
 	var shoot_attempt = Input.is_action_pressed("shoot")
 	
-	var target_dir = (dir - up * dir.dot(up)).normalized()
-	
 	if is_on_floor():
-		var sharp_turn = hspeed > 0.1 and rad2deg(acos(target_dir.dot(hdir))) > sharp_turn_threshold
+		var sharp_turn = hspeed > 0.1 and rad2deg(acos(dir.dot(hdir))) > sharp_turn_threshold
 		
 		if dir.length() > 0.1 and !sharp_turn:
 			if hspeed > 0.001:
-				#linear_dir = linear_h_velocity/linear_vel
-				#if (linear_vel > brake_velocity_limit and linear_dir.dot(ctarget_dir) < -cos(Math::deg2rad(brake_angular_limit)))
-				#	brake = true
-				#else
-				hdir = adjust_facing(hdir, target_dir, delta, 1.0 / hspeed * turn_speed, up)
+				hdir = adjust_facing(hdir, dir, delta, 1.0 / hspeed * TURN_SPEED, Vector3.UP)
 				facing_dir = hdir
 			else:
-				hdir = target_dir
+				hdir = dir
 			
 			if hspeed < max_speed:
 				hspeed += accel * delta
@@ -117,11 +75,11 @@ func _physics_process(delta):
 		
 		var mesh_xform = get_node("Armature").get_transform()
 		var facing_mesh = -mesh_xform.basis[0].normalized()
-		facing_mesh = (facing_mesh - up * facing_mesh.dot(up)).normalized()
+		facing_mesh = (facing_mesh - Vector3.UP * facing_mesh.dot(Vector3.UP)).normalized()
 		
-		if hspeed>0:
-			facing_mesh = adjust_facing(facing_mesh, target_dir, delta, 1.0/hspeed*turn_speed, up)
-		var m3 = Basis(-facing_mesh, up, -facing_mesh.cross(up).normalized()).scaled(CHAR_SCALE)
+		if hspeed > 0:
+			facing_mesh = adjust_facing(facing_mesh, dir, delta, 1.0 / hspeed * TURN_SPEED, Vector3.UP)
+		var m3 = Basis(-facing_mesh, Vector3.UP, -facing_mesh.cross(Vector3.UP).normalized()).scaled(CHAR_SCALE)
 		
 		get_node("Armature").set_transform(Transform(m3, mesh_xform.origin))
 		
@@ -135,14 +93,13 @@ func _physics_process(delta):
 		else:
 			anim = ANIM_AIR_DOWN
 		
-		# var hs
 		if dir.length() > 0.1:
-			hv += target_dir * (accel * 0.2) * delta
-			if (hv.length() > max_speed):
-				hv = hv.normalized()*max_speed
+			hv += dir * (accel * 0.2 * delta)
+			if hv.length() > max_speed:
+				hv = hv.normalized() * max_speed
 		else:
 			if air_idle_deaccel:
-				hspeed = hspeed - (deaccel * 0.2) * delta
+				hspeed = hspeed - (deaccel * 0.2 * delta)
 				if hspeed < 0:
 					hspeed = 0
 				hv = hdir * hspeed
@@ -150,12 +107,12 @@ func _physics_process(delta):
 	if jumping and vv < 0:
 		jumping = false
 	
-	lv = hv + up*vv
+	linear_velocity = hv + Vector3.UP * vv
 	
 	if is_on_floor():
-		movement_dir = lv
+		movement_dir = linear_velocity
 		
-	linear_velocity = move_and_slide(lv,-g.normalized())
+	linear_velocity = move_and_slide(linear_velocity, -gravity.normalized())
 	
 	if shoot_blend > 0:
 		shoot_blend -= delta * SHOOT_SCALE
@@ -168,7 +125,7 @@ func _physics_process(delta):
 		bullet.set_transform(get_node("Armature/Bullet").get_global_transform().orthonormalized())
 		get_parent().add_child(bullet)
 		bullet.set_linear_velocity(get_node("Armature/Bullet").get_global_transform().basis[2].normalized() * 20)
-		bullet.add_collision_exception_with(self) # Add it to bullet
+		bullet.add_collision_exception_with(self) # Add it to bullet.
 		get_node("SoundShoot").play()
 	
 	prev_shoot = shoot_attempt
@@ -178,8 +135,28 @@ func _physics_process(delta):
 	
 	get_node("AnimationTreePlayer").transition_node_set_current("state", anim)
 	get_node("AnimationTreePlayer").blend2_node_set_amount("gun", min(shoot_blend, 1.0))
-#	state.set_angular_velocity(Vector3())
 
 
-func _ready():
-	get_node("AnimationTreePlayer").set_active(true)
+func adjust_facing(p_facing, p_target, p_step, p_adjust_rate, current_gn):
+	var n = p_target # Normal.
+	var t = n.cross(current_gn).normalized()
+	 
+	var x = n.dot(p_facing)
+	var y = t.dot(p_facing)
+	
+	var ang = atan2(y,x)
+	
+	if abs(ang) < 0.001: # Too small.
+		return p_facing
+	
+	var s = sign(ang)
+	ang = ang * s
+	var turn = ang * p_adjust_rate * p_step
+	var a
+	if ang < turn:
+		a = ang
+	else:
+		a = turn
+	ang = (ang - a) * s
+	
+	return (n * cos(ang) + t * sin(ang)) * p_facing.length()

+ 7 - 7
3d/platformer/player.tscn

@@ -1828,12 +1828,18 @@ data = {
 "type": "animation"
 }, {
 "blend": 1.0,
-"filter": [ NodePath("Armature/Skeleton:r-leg"), NodePath("Armature/Skeleton:r-foot"), NodePath("Armature/Skeleton:r-LEGORIENT"), NodePath("Armature/Skeleton:r-LEGCONTROL"), NodePath("Armature/Skeleton:r-ARMORIENT"), NodePath("Armature/Skeleton:r-ARMCONTROL"), NodePath("Armature/Skeleton:waist"), NodePath("Armature/Skeleton:neck"), NodePath("Armature/Skeleton:l-leg"), NodePath("Armature/Skeleton:l-foot"), NodePath("Armature/Skeleton:hip"), NodePath("Armature/Skeleton:head"), NodePath("Armature/Skeleton:HEAD"), NodePath("Armature/Skeleton:l-LEGORIENT"), NodePath("Armature/Skeleton:l-LEGCONTROL"), NodePath("Armature/Skeleton:l-ARMORIENT"), NodePath("Armature/Skeleton:l-ARMCONTROL"), NodePath("Armature/Skeleton:r-thigh"), NodePath("Armature/Skeleton:MASTER"), NodePath("Armature"), NodePath("Armature/Skeleton:l-thigh"), NodePath("Armature/Skeleton:headtracker") ],
+"filter": [ NodePath("Armature/Skeleton:r-foot"), NodePath("Armature/Skeleton:r-leg"), NodePath("Armature/Skeleton:waist"), NodePath("Armature/Skeleton:r-ARMCONTROL"), NodePath("Armature/Skeleton:r-ARMORIENT"), NodePath("Armature/Skeleton:r-LEGCONTROL"), NodePath("Armature/Skeleton:r-LEGORIENT"), NodePath("Armature/Skeleton:hip"), NodePath("Armature/Skeleton:l-foot"), NodePath("Armature/Skeleton:l-leg"), NodePath("Armature/Skeleton:neck"), NodePath("Armature/Skeleton:l-ARMCONTROL"), NodePath("Armature/Skeleton:l-ARMORIENT"), NodePath("Armature/Skeleton:l-LEGCONTROL"), NodePath("Armature/Skeleton:l-LEGORIENT"), NodePath("Armature/Skeleton:HEAD"), NodePath("Armature/Skeleton:head"), NodePath("Armature/Skeleton:r-thigh"), NodePath("Armature/Skeleton:MASTER"), NodePath("Armature/Skeleton:l-thigh"), NodePath("Armature"), NodePath("Armature/Skeleton:headtracker") ],
 "id": "gun",
 "position": Vector2( 779, 489 ),
 "type": "blend2"
 }, {
 "filter": [  ],
+"from": "walk-cycle",
+"id": "anim 2",
+"position": Vector2( 44, 202 ),
+"type": "animation"
+}, {
+"filter": [  ],
 "from": "falling-cycle",
 "id": "anim 4",
 "position": Vector2( 46, 419 ),
@@ -1844,12 +1850,6 @@ data = {
 "id": "walk",
 "position": Vector2( 309, 182 ),
 "type": "blend2"
-}, {
-"filter": [  ],
-"from": "walk-cycle",
-"id": "anim 2",
-"position": Vector2( 44, 202 ),
-"type": "animation"
 } ]
 }
 

+ 12 - 0
3d/platformer/project.godot

@@ -92,31 +92,43 @@ ui_page_down={
 move_forward={
 "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":16777232,"unicode":0,"echo":false,"script":null)
+, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":87,"unicode":0,"echo":false,"script":null)
+, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":-1.0,"script":null)
  ]
 }
 move_backwards={
 "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":16777234,"unicode":0,"echo":false,"script":null)
+, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":83,"unicode":0,"echo":false,"script":null)
+, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":1.0,"script":null)
  ]
 }
 move_left={
 "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":16777231,"unicode":0,"echo":false,"script":null)
+, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":65,"unicode":0,"echo":false,"script":null)
+, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":-1.0,"script":null)
  ]
 }
 move_right={
 "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":16777233,"unicode":0,"echo":false,"script":null)
+, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":68,"unicode":0,"echo":false,"script":null)
+, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":1.0,"script":null)
  ]
 }
 jump={
 "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":32,"unicode":0,"echo":false,"script":null)
+, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":0,"pressure":0.0,"pressed":false,"script":null)
  ]
 }
 shoot={
 "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":90,"unicode":0,"echo":false,"script":null)
+, 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)
+, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":1,"pressure":0.0,"pressed":false,"script":null)
+, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":7,"pressure":0.0,"pressed":false,"script":null)
  ]
 }
 

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 0 - 14
3d/platformer/robotrigged.tscn


La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 1 - 1
3d/platformer/stage.tscn


BIN
3d/platformer/tiles.res


La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 28 - 0
3d/platformer/tiles.tres


La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 2 - 3
3d/platformer/tiles.tscn


Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio