OverviewFilesCommitsIssuesDocsReleasesPeers

godot-marble_madness_demo commits / 4670c83

rename detection Gitty?
4670c838abc71697a00e85b01c0b6d3dc8b9d799
by Dresk Spidflisk <dreskspidflisk@gmail.com> · 2022-02-03T23:27:28.000Z

Changed files (6) +169 -159

levels/level_script.gd +6 -0
……@@ -82,6 +82,7 @@ func get_player_object(id):
8282 return remotePlayer
8383
8484func _broadcast_player():
85 var physics : int = player_local.mode
8586 var translation : Vector3 = player_local.translation
8687 var rotation : Vector3 = player_local.rotation_degrees
8788 var velocity_linear : Vector3 = player_local.linear_velocity
……@@ -89,6 +90,9 @@ func _broadcast_player():
8990
9091 var data = {
9192 #"profile": profile,
93 "physics": {
94 "mode": physics
95 },
9296 "translation": {
9397 "x": translation.x,
9498 "y": translation.y,
……@@ -117,12 +121,14 @@ func _on_remote_player_moved(positionData, id):
117121 # print('Moving player', id, " ", positionData)
118122 var remotePlayer = get_player_object(id)
119123
124 var physics : int = int(positionData.physics.mode)
120125 var translation : Vector3 = Vector3(positionData.translation.x, positionData.translation.y, positionData.translation.z)
121126 var rotation : Vector3 = Vector3(positionData.rotation.x, positionData.rotation.y, positionData.rotation.z)
122127 var velocity_linear : Vector3 = Vector3(positionData.velocity_linear.x, positionData.velocity_linear.y, positionData.velocity_linear.z)
123128 var velocity_angular : Vector3 = Vector3(positionData.velocity_angular.x, positionData.velocity_angular.y, positionData.velocity_angular.z)
124129
125130 remotePlayer.update_position(
131 physics,
126132 translation,
127133 rotation,
128134 velocity_linear,
levels/scenes/level_0.tscn +7 -2
……@@ -1,4 +1,4 @@
1[gd_scene load_steps=14 format=2]
1[gd_scene load_steps=16 format=2]
22
33[ext_resource path="res://assets/levels/level0/assets_level_0.tscn" type="PackedScene" id=1]
44[ext_resource path="res://levels/spawn_point/spawn_point.tscn" type="PackedScene" id=2]
……@@ -13,6 +13,8 @@
1313[ext_resource path="res://hypergodot/hyper_gossip/hyper_gossip.gd" type="Script" id=11]
1414[ext_resource path="res://ui/debug/hypercore/ui_debug_hypercore.tscn" type="PackedScene" id=12]
1515[ext_resource path="res://ui/PlayerConfig.tscn" type="PackedScene" id=13]
16[ext_resource path="res://player/ball/player_ball_remote.tscn" type="PackedScene" id=14]
17[ext_resource path="res://player/ball/player_ball_controller.gd" type="Script" id=15]
1618
1719[node name="Spatial" type="Node"]
1820script = ExtResource( 3 )
……@@ -24,12 +26,16 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 1.178, 1.877, -3.673 )
2426
2527[node name="PlayerLocal" parent="Players" instance=ExtResource( 4 )]
2628transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.733258, 2.26544, -8.91449 )
29script = ExtResource( 15 )
2730
2831[node name="PlayerLocalCamera" parent="Players" instance=ExtResource( 7 )]
2932pause_mode = 2
3033script = ExtResource( 8 )
3134player_ball = NodePath("../PlayerLocal")
3235
36[node name="PlayerBallRemote" parent="Players" instance=ExtResource( 14 )]
37transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 1.03321, 1.38366, -6.26667 )
38
3339[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
3440environment = ExtResource( 9 )
3541
……@@ -68,7 +74,6 @@ script = ExtResource( 11 )
6874[node name="GossipEventTimer" type="Timer" parent="HyperGodot"]
6975autostart = true
7076
71[connection signal="moved" from="Players/PlayerLocal" to="." method="_on_PlayerLocal_moved"]
7277[connection signal="reset_ball" from="special_input" to="Players/PlayerLocal" method="_on_special_input_reset_ball"]
7378[connection signal="started_gateway" from="HyperGodot/HyperGateway" to="." method="_on_HyperGateway_started_gateway"]
7479[connection signal="stopped_gateway" from="HyperGodot/HyperGateway" to="." method="_on_HyperGateway_stopped_gateway"]
player/ball/player_ball.gd +0 -152
……@@ -1,152 +0,0 @@
1extends RigidBody
2
3enum BallPhysicsMode {
4 FREE_FLY,
5 ENGINE_PHYSICS_ROLL,
6 ENGINE_PHYSICS_LINEAR,
7 PHYSICS_MAX
8}
9
10signal moved
11
12var rolling_force : float = 10.0
13var rolling_force_max : float = 50.0
14
15var linear_force : float = 2.0
16
17var freefly_force : float = 3.0
18
19onready var ballInitialOrigin : Vector3 = self.translation
20
21var ball_physics_mode : int = BallPhysicsMode.ENGINE_PHYSICS_LINEAR
22var bFirstPersonCamera = false
23
24var lVelocity : Label
25var lAngularVelocity : Label
26var lBallPhysicsMode : Label
27
28func _ready():
29 lVelocity = get_tree().get_current_scene().get_node("BallDebugUI").find_node("BallVelocity_Value")
30 lAngularVelocity = get_tree().get_current_scene().get_node("BallDebugUI").find_node("BallAngularVelocity_Value")
31 lBallPhysicsMode = get_tree().get_current_scene().get_node("BallDebugUI").find_node("BallPhysicsMode_Value")
32
33 updateBallPhysicsMode()
34
35func _process(_delta: float) -> void:
36 pass
37
38func resetBall() -> void:
39 self.angular_velocity = Vector3(0, 0, 0)
40 self.linear_velocity = Vector3(0, 0, 0)
41 self.rotation = Vector3(0, 0, 0)
42 ball_physics_mode = BallPhysicsMode.ENGINE_PHYSICS_LINEAR
43 updateBallPhysicsMode()
44 self.translation = ballInitialOrigin
45
46func updateBallPhysicsMode() -> void:
47 if(ball_physics_mode == BallPhysicsMode.FREE_FLY):
48 lBallPhysicsMode.text = "Free Fly"
49 self.angular_velocity = Vector3(0, 0, 0)
50 self.rotation = Vector3(0, 0, 0)
51 self.linear_velocity = Vector3(0, 0, 0)
52 self.mode = RigidBody.MODE_STATIC
53 elif(ball_physics_mode == BallPhysicsMode.ENGINE_PHYSICS_ROLL):
54 lBallPhysicsMode.text = "Engine Physics (Roll)"
55 self.physics_material_override.friction = 1.0
56 self.mode = RigidBody.MODE_RIGID
57 else:
58 lBallPhysicsMode.text = "Engine Physics (Linear)"
59 self.physics_material_override.friction = 0.035
60 self.mode = RigidBody.MODE_RIGID
61
62func checkAngularVelocity(delta : float, angVelocity : float, bAdd : bool) -> float:
63 if bAdd:
64 angVelocity = angVelocity + rolling_force*delta
65 else:
66 angVelocity = angVelocity - rolling_force*delta
67
68 var cappedVelocity = min(rolling_force_max, abs(angVelocity) )
69 if (angVelocity < 0):
70 return cappedVelocity * -1
71 else:
72 return cappedVelocity
73
74func _physics_process(delta: float) -> void:
75 #if Input.is_action_just_pressed("camera_toggle_fps"):
76 # if bFirstPersonCamera == true:
77 # bFirstPersonCamera = false
78 # ballCamera.global_transform.origin = ballCameraOriginalOrigin
79 # else:
80 # bFirstPersonCamera = true
81
82 #if false:
83 # ballCamera.global_transform.origin = lerp(
84 # ballCamera.global_transform.origin,
85 # global_transform.origin, 1.0
86 # )
87 # ballCamera.global_transform.origin = lerp(
88 # ballCamera.global_transform.origin,
89 # global_transform.origin, 1.0
90 # )
91
92 if Input.is_action_just_pressed("ball_cycle_physics_mode"):
93 ball_physics_mode = (ball_physics_mode + 1) % BallPhysicsMode.PHYSICS_MAX
94 if(ball_physics_mode == BallPhysicsMode.FREE_FLY):
95 self.mode = RigidBody.MODE_STATIC
96 else:
97 self.mode = RigidBody.MODE_RIGID
98 updateBallPhysicsMode()
99
100
101 #if(ball_physics_mode == BallPhysicsMode.FREE_FLY):
102 # return
103
104 if Input.is_action_pressed("ball_roll_up"):
105 if(ball_physics_mode == BallPhysicsMode.ENGINE_PHYSICS_ROLL):
106 angular_velocity.x = clamp(angular_velocity.x - rolling_force*delta, rolling_force_max * -1, rolling_force_max)
107 elif(ball_physics_mode == BallPhysicsMode.FREE_FLY):
108 self.translate( Vector3(0, 0, -freefly_force) * delta)
109 else:
110 linear_velocity.z -= (linear_force * delta);
111 elif Input.is_action_pressed("ball_roll_down"):
112 if(ball_physics_mode == BallPhysicsMode.ENGINE_PHYSICS_ROLL):
113 angular_velocity.x = clamp(angular_velocity.x + rolling_force*delta, rolling_force_max * -1, rolling_force_max)
114 elif(ball_physics_mode == BallPhysicsMode.FREE_FLY):
115 self.translate( Vector3(0, 0, freefly_force) * delta)
116 else:
117 linear_velocity.z += (linear_force * delta);
118
119 if Input.is_action_pressed("ball_roll_left"):
120 if(ball_physics_mode == BallPhysicsMode.ENGINE_PHYSICS_ROLL):
121 angular_velocity.z = clamp(angular_velocity.z + rolling_force*delta, rolling_force_max * -1, rolling_force_max)
122 elif(ball_physics_mode == BallPhysicsMode.FREE_FLY):
123 self.translate( Vector3(-freefly_force, 0, 0) * delta)
124 else:
125 linear_velocity.x -= (linear_force * delta);
126 elif Input.is_action_pressed("ball_roll_right"):
127 if(ball_physics_mode == BallPhysicsMode.ENGINE_PHYSICS_ROLL):
128 angular_velocity.z = clamp(angular_velocity.z - rolling_force*delta, rolling_force_max * -1, rolling_force_max)
129 elif(ball_physics_mode == BallPhysicsMode.FREE_FLY):
130 self.translate( Vector3(freefly_force, 0, 0) * delta)
131 else:
132 linear_velocity.x += (linear_force * delta);
133
134 if Input.is_action_pressed("ball_fly_up"):
135 if(ball_physics_mode == BallPhysicsMode.FREE_FLY):
136 self.translate( Vector3(0, freefly_force, 0) * delta)
137 elif Input.is_action_pressed("ball_fly_down"):
138 if(ball_physics_mode == BallPhysicsMode.FREE_FLY):
139 self.translate( Vector3(0, -freefly_force, 0) * delta)
140
141 #if Input.is_action_just_pressed("jump") and $FloorCheck.is_colliding():
142 # apply_impulse(Vector3(), Vector3.UP*1000)
143
144 # Update Debug UI
145 lVelocity.text = String(self.linear_velocity)
146 lAngularVelocity.text = String(self.angular_velocity)
147
148func _on_PlayerLocal_reset_ball() -> void:
149 resetBall()
150
151func _on_special_input_reset_ball() -> void:
152 resetBall()
player/ball/player_ball.tscn +1 -3
……@@ -1,7 +1,6 @@
1[gd_scene load_steps=5 format=2]
1[gd_scene load_steps=4 format=2]
22
33[ext_resource path="res://assets/models/pixar-ball/pixar-ball.tscn" type="PackedScene" id=1]
4[ext_resource path="res://player/ball/player_ball.gd" type="Script" id=2]
54
65[sub_resource type="PhysicsMaterial" id=2]
76friction = 0.0
……@@ -11,7 +10,6 @@ rough = true
1110
1211[node name="PlayerBall" type="RigidBody"]
1312physics_material_override = SubResource( 2 )
14script = ExtResource( 2 )
1513
1614[node name="CollisionShape" type="CollisionShape" parent="."]
1715transform = Transform( 0.1, 0, 0, 0, 0.1, 0, 0, 0, 0.1, 0, 0, 0 )
player/ball/player_ball_controller.gd +152 -0
……@@ -0,0 +1,152 @@
1extends RigidBody
2
3enum BallPhysicsMode {
4 FREE_FLY,
5 ENGINE_PHYSICS_ROLL,
6 ENGINE_PHYSICS_LINEAR,
7 PHYSICS_MAX
8}
9
10signal moved
11
12var rolling_force : float = 10.0
13var rolling_force_max : float = 50.0
14
15var linear_force : float = 2.0
16
17var freefly_force : float = 3.0
18
19onready var ballInitialOrigin : Vector3 = self.translation
20
21var ball_physics_mode : int = BallPhysicsMode.ENGINE_PHYSICS_LINEAR
22var bFirstPersonCamera = false
23
24var lVelocity : Label
25var lAngularVelocity : Label
26var lBallPhysicsMode : Label
27
28func _ready():
29 lVelocity = get_tree().get_current_scene().get_node("BallDebugUI").find_node("BallVelocity_Value")
30 lAngularVelocity = get_tree().get_current_scene().get_node("BallDebugUI").find_node("BallAngularVelocity_Value")
31 lBallPhysicsMode = get_tree().get_current_scene().get_node("BallDebugUI").find_node("BallPhysicsMode_Value")
32
33 updateBallPhysicsMode()
34
35func _process(_delta: float) -> void:
36 pass
37
38func resetBall() -> void:
39 self.angular_velocity = Vector3(0, 0, 0)
40 self.linear_velocity = Vector3(0, 0, 0)
41 self.rotation = Vector3(0, 0, 0)
42 ball_physics_mode = BallPhysicsMode.ENGINE_PHYSICS_LINEAR
43 updateBallPhysicsMode()
44 self.translation = ballInitialOrigin
45
46func updateBallPhysicsMode() -> void:
47 if(ball_physics_mode == BallPhysicsMode.FREE_FLY):
48 lBallPhysicsMode.text = "Free Fly"
49 self.angular_velocity = Vector3(0, 0, 0)
50 self.rotation = Vector3(0, 0, 0)
51 self.linear_velocity = Vector3(0, 0, 0)
52 self.mode = RigidBody.MODE_STATIC
53 elif(ball_physics_mode == BallPhysicsMode.ENGINE_PHYSICS_ROLL):
54 lBallPhysicsMode.text = "Engine Physics (Roll)"
55 self.physics_material_override.friction = 1.0
56 self.mode = RigidBody.MODE_RIGID
57 else:
58 lBallPhysicsMode.text = "Engine Physics (Linear)"
59 self.physics_material_override.friction = 0.035
60 self.mode = RigidBody.MODE_RIGID
61
62func checkAngularVelocity(delta : float, angVelocity : float, bAdd : bool) -> float:
63 if bAdd:
64 angVelocity = angVelocity + rolling_force*delta
65 else:
66 angVelocity = angVelocity - rolling_force*delta
67
68 var cappedVelocity = min(rolling_force_max, abs(angVelocity) )
69 if (angVelocity < 0):
70 return cappedVelocity * -1
71 else:
72 return cappedVelocity
73
74func _physics_process(delta: float) -> void:
75 #if Input.is_action_just_pressed("camera_toggle_fps"):
76 # if bFirstPersonCamera == true:
77 # bFirstPersonCamera = false
78 # ballCamera.global_transform.origin = ballCameraOriginalOrigin
79 # else:
80 # bFirstPersonCamera = true
81
82 #if false:
83 # ballCamera.global_transform.origin = lerp(
84 # ballCamera.global_transform.origin,
85 # global_transform.origin, 1.0
86 # )
87 # ballCamera.global_transform.origin = lerp(
88 # ballCamera.global_transform.origin,
89 # global_transform.origin, 1.0
90 # )
91
92 if Input.is_action_just_pressed("ball_cycle_physics_mode"):
93 ball_physics_mode = (ball_physics_mode + 1) % BallPhysicsMode.PHYSICS_MAX
94 if(ball_physics_mode == BallPhysicsMode.FREE_FLY):
95 self.mode = RigidBody.MODE_STATIC
96 else:
97 self.mode = RigidBody.MODE_RIGID
98 updateBallPhysicsMode()
99
100
101 #if(ball_physics_mode == BallPhysicsMode.FREE_FLY):
102 # return
103
104 if Input.is_action_pressed("ball_roll_up"):
105 if(ball_physics_mode == BallPhysicsMode.ENGINE_PHYSICS_ROLL):
106 angular_velocity.x = clamp(angular_velocity.x - rolling_force*delta, rolling_force_max * -1, rolling_force_max)
107 elif(ball_physics_mode == BallPhysicsMode.FREE_FLY):
108 self.translate( Vector3(0, 0, -freefly_force) * delta)
109 else:
110 linear_velocity.z -= (linear_force * delta);
111 elif Input.is_action_pressed("ball_roll_down"):
112 if(ball_physics_mode == BallPhysicsMode.ENGINE_PHYSICS_ROLL):
113 angular_velocity.x = clamp(angular_velocity.x + rolling_force*delta, rolling_force_max * -1, rolling_force_max)
114 elif(ball_physics_mode == BallPhysicsMode.FREE_FLY):
115 self.translate( Vector3(0, 0, freefly_force) * delta)
116 else:
117 linear_velocity.z += (linear_force * delta);
118
119 if Input.is_action_pressed("ball_roll_left"):
120 if(ball_physics_mode == BallPhysicsMode.ENGINE_PHYSICS_ROLL):
121 angular_velocity.z = clamp(angular_velocity.z + rolling_force*delta, rolling_force_max * -1, rolling_force_max)
122 elif(ball_physics_mode == BallPhysicsMode.FREE_FLY):
123 self.translate( Vector3(-freefly_force, 0, 0) * delta)
124 else:
125 linear_velocity.x -= (linear_force * delta);
126 elif Input.is_action_pressed("ball_roll_right"):
127 if(ball_physics_mode == BallPhysicsMode.ENGINE_PHYSICS_ROLL):
128 angular_velocity.z = clamp(angular_velocity.z - rolling_force*delta, rolling_force_max * -1, rolling_force_max)
129 elif(ball_physics_mode == BallPhysicsMode.FREE_FLY):
130 self.translate( Vector3(freefly_force, 0, 0) * delta)
131 else:
132 linear_velocity.x += (linear_force * delta);
133
134 if Input.is_action_pressed("ball_fly_up"):
135 if(ball_physics_mode == BallPhysicsMode.FREE_FLY):
136 self.translate( Vector3(0, freefly_force, 0) * delta)
137 elif Input.is_action_pressed("ball_fly_down"):
138 if(ball_physics_mode == BallPhysicsMode.FREE_FLY):
139 self.translate( Vector3(0, -freefly_force, 0) * delta)
140
141 #if Input.is_action_just_pressed("jump") and $FloorCheck.is_colliding():
142 # apply_impulse(Vector3(), Vector3.UP*1000)
143
144 # Update Debug UI
145 lVelocity.text = String(self.linear_velocity)
146 lAngularVelocity.text = String(self.angular_velocity)
147
148func _on_PlayerLocal_reset_ball() -> void:
149 resetBall()
150
151func _on_special_input_reset_ball() -> void:
152 resetBall()
player/ball/player_ball_remote.gd +3 -2
……@@ -1,6 +1,7 @@
1extends "res://player/ball/player_ball.gd"
1extends RigidBody
22
3func update_position(new_translation : Vector3, new_rotation : Vector3, new_velocity_linear : Vector3, new_velocity_angular : Vector3):
3func update_position(new_mode : int, new_translation : Vector3, new_rotation : Vector3, new_velocity_linear : Vector3, new_velocity_angular : Vector3):
4 self.mode = new_mode
45 self.translation = new_translation
56 self.rotation = new_rotation
67 self.linear_velocity = new_velocity_linear