Skip to content

Commit

Permalink
Add support for VIVE Trackers
Browse files Browse the repository at this point in the history
Better crunches
  • Loading branch information
mgschwan committed Jun 29, 2020
1 parent 1a0cdba commit 83fb136
Show file tree
Hide file tree
Showing 16 changed files with 200 additions and 122 deletions.
6 changes: 4 additions & 2 deletions godot_project/ControllerAdjuster.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@ func _ready():

func touched_by_controller(obj, root):
if current_controller == null:
print ("Fix controller: %s"%str(obj))
current_controller = obj #get_tree().current_scene.left_controller

for t in GameVariables.trackers:
if t and t.controller_id != current_controller.id:
if t and t.controller_id != current_controller.controller_id:
t.fix_global_transform(true)


func released_by_controller(obj, root):
if current_controller != null:
print ("Release controller")
for t in GameVariables.trackers:
if t and t.controller_id != current_controller.id:
if t and t.controller_id != current_controller.controller_id:
t.fix_global_transform(false)
current_controller = null

Expand Down
9 changes: 6 additions & 3 deletions godot_project/ControllerScript.gd
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,16 @@ func _on_RumbleTimer_timeout():
get_node("Area/bad_hit").hide()
self.set_rumble(0.0)

#Resize the controller to make menu selection easier


#Resize the collision area to make menu selection easier
func set_detail_select(value):
var main_area = get_node("Area/CollisionShape")
if value:
print ("Set detail mode")
get_node("Area").scale = Vector3(0.2,0.2,0.2)
main_area.scale = Vector3(0.05,0.05,0.05)
else:
get_node("Area").scale = Vector3(1.0,1.0,1.0)
main_area.scale = Vector3(0.1,0.1,0.1)



14 changes: 7 additions & 7 deletions godot_project/Left_Controller_Tree.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -26,38 +26,38 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.5, 1.6, 0 )
script = ExtResource( 2 )

[node name="Area" type="Area" parent="."]
transform = Transform( 0.5, -0.866025, 0, 0.866025, 0.5, 0, 0, 0, 1, 0, 0, 0.12 )
transform = Transform( 0.5, -0.866025, 0, 0.866025, 0.5, 0, 0, 0, 1, 0, 0, 0 )
script = ExtResource( 1 )

[node name="CollisionShape" type="CollisionShape" parent="Area"]
transform = Transform( 0.1, -3.72529e-09, 0, 3.72529e-09, 0.1, 0, 0, 0, 0.1, 0, 0, -0.0654641 )
transform = Transform( 0.1, -3.72529e-09, 0, 3.72529e-09, 0.1, 0, 0, 0, 0.1, 0, 0, 0 )
shape = SubResource( 1 )

[node name="Spatial" parent="Area" instance=ExtResource( 9 )]
transform = Transform( -0.2, -7.45058e-09, -3.01992e-08, -7.45058e-09, 0.2, 0, 3.01992e-08, 0, -0.2, 2.38419e-07, 0.0224875, 0.0321004 )
transform = Transform( -0.2, -7.45058e-09, -3.01992e-08, -7.45058e-09, 0.2, 0, 3.01992e-08, 0, -0.2, 0, 0.022, 0.09 )
visible = false

[node name="hit_player" type="AudioStreamPlayer" parent="Area"]
stream = ExtResource( 5 )
volume_db = -2.5

[node name="handle_ball" parent="Area" instance=ExtResource( 10 )]
transform = Transform( 0.05, -1.86265e-09, 0, 1.86265e-09, 0.05, 0, 0, 0, 0.05, 0, 0, -0.12 )
transform = Transform( 0.05, -1.86265e-09, 0, 1.86265e-09, 0.05, 0, 0, 0, 0.05, 0, 0, 0 )

[node name="good_hit" type="MeshInstance" parent="Area"]
transform = Transform( 0.05, 0.0866026, 0, -0.0866026, 0.05, 0, 0, 0, 0.1, 0, 0, -0.12 )
transform = Transform( 0.05, 0.0866026, 0, -0.0866026, 0.05, 0, 0, 0, 0.1, 0, 0, 0 )
visible = false
mesh = SubResource( 2 )
material/0 = ExtResource( 4 )

[node name="bad_hit" type="MeshInstance" parent="Area"]
transform = Transform( 0.05, 0.0866026, 0, -0.0866026, 0.05, 0, 0, 0, 0.1, 0, 0, -0.12 )
transform = Transform( 0.05, 0.0866026, 0, -0.0866026, 0.05, 0, 0, 0, 0.1, 0, 0, 0 )
visible = false
mesh = SubResource( 2 )
material/0 = ExtResource( 6 )

[node name="hand_model" parent="Area" instance=ExtResource( 7 )]
transform = Transform( 0.5, 0.866026, 0, -0.866026, 0.5, 0, 0, 0, 1, 0, 0, -0.12 )
transform = Transform( 0.5, 0.866026, 0, -0.866026, 0.5, 0, 0, 0, 1, 0, 0, 0 )

[node name="forearm" parent="Area/hand_model" instance=ExtResource( 8 )]
transform = Transform( -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 0, 0, 1, -0.288121, 1.19209e-07, 0 )
Expand Down
29 changes: 19 additions & 10 deletions godot_project/Level.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=32 format=2]
[gd_scene load_steps=33 format=2]

[ext_resource path="res://Main.gd" type="Script" id=1]
[ext_resource path="res://spawn_timer.gd" type="Script" id=2]
Expand Down Expand Up @@ -47,12 +47,18 @@ flags_transparent = true
vertex_color_use_as_albedo = true
albedo_texture = SubResource( 4 )

[sub_resource type="CubeMesh" id=6]
[sub_resource type="Curve3D" id=6]
_data = {
"points": PoolVector3Array( 0, 0, 0, 0, 0, 0, -0.393426, 1.02695, 0.270852, 0, 0, 0, 0, 0, 0, 1.54268, 1.03279, 2.26938, 0, 0, 0, 0, 0, 0, 1.76955, 0.993884, 6.47424, 0, 0, 0, 0, 0, 0, -0.0516853, 1.12288, 8.81755 ),
"tilts": PoolRealArray( 0, 0, 0, 0 )
}

[sub_resource type="BoxShape" id=7]
[sub_resource type="CubeMesh" id=7]

[sub_resource type="BoxShape" id=8]
extents = Vector3( 0.455611, 0.0926839, 0.161588 )

[sub_resource type="SpatialMaterial" id=8]
[sub_resource type="SpatialMaterial" id=9]
albedo_color = Color( 0.94902, 0.937255, 0.937255, 1 )
albedo_texture = ExtResource( 23 )

Expand Down Expand Up @@ -101,6 +107,9 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.51152, 0 )
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.959816, 0 )
aabb = AABB( -1, -0.256859, -1, 2, 0.513717, 2 )

[node name="Path" type="Path" parent="cue_emitter"]
curve = SubResource( 6 )

[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."]
bus = "Music"

Expand All @@ -109,24 +118,24 @@ transform = Transform( 0.118828, 0, 0, 0, 1, 0, 0, 0, 0.0898216, -0.87, 1, -0.06

[node name="target_zone_l" type="MeshInstance" parent="target"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -2.7525, 0, 0 )
mesh = SubResource( 6 )
mesh = SubResource( 7 )
material/0 = ExtResource( 11 )

[node name="target_zone_l2" type="MeshInstance" parent="target"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 17.5653, 0, 0 )
mesh = SubResource( 6 )
mesh = SubResource( 7 )
material/0 = ExtResource( 11 )

[node name="target_zone_l3" type="MeshInstance" parent="target"]
transform = Transform( 0.866025, 4.20776, 1.65206e-08, -0.00129093, 0.0188166, 0.0898004, 0.661311, -9.63934, 0.0217276, 12.525, -1.07, -11.5 )
visible = false
mesh = SubResource( 6 )
mesh = SubResource( 7 )
material/0 = ExtResource( 10 )

[node name="target_zone_l4" type="MeshInstance" parent="target"]
transform = Transform( 0.866025, -4.20776, -1.65206e-08, 0.00129093, 0.0188166, 0.0898004, -0.661311, -9.63934, 0.0217276, 2.276, -1.07, -11.5 )
visible = false
mesh = SubResource( 6 )
mesh = SubResource( 7 )
material/0 = ExtResource( 10 )

[node name="exit_button" type="StaticBody" parent="target"]
Expand All @@ -139,7 +148,7 @@ default_text = "EXIT STAGE"

[node name="CollisionShape" type="CollisionShape" parent="target/exit_button"]
transform = Transform( 1, -3.55271e-15, 2.64698e-23, 0, 1, -1.77636e-15, 3.38813e-21, -2.84217e-14, 1, -0.688979, 0, -0.413249 )
shape = SubResource( 7 )
shape = SubResource( 8 )

[node name="PositionSign" parent="." instance=ExtResource( 9 )]
transform = Transform( 0.5, 0, 0, 0, -4.37114e-08, -0.5, 0, 1, -2.18557e-08, -1.79988, 0.513339, -4.91669 )
Expand Down Expand Up @@ -179,7 +188,7 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.026268, -0.001, -0.586 )
[node name="mat_simple" parent="MainStage" instance=ExtResource( 22 )]
transform = Transform( -6.99382e-10, 0, 0.018, 0, 0.02, 0, -0.016, 0, -7.86805e-10, 0.109178, -0.01, 0.493 )
visible = false
material/0 = SubResource( 8 )
material/0 = SubResource( 9 )

[node name="mat" parent="MainStage" instance=ExtResource( 24 )]
transform = Transform( 0.19, 0, 0, 0, 0.2, 0, 0, 0, 0.19, 0.0230895, 0.00996999, 0.522808 )
Expand Down
38 changes: 1 addition & 37 deletions godot_project/Levelselect.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -55,42 +55,6 @@ height = 0.2
transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 0, 0, 1.6 )
script = ExtResource( 1 )

[node name="Level1" parent="." instance=ExtResource( 6 )]
transform = Transform( -8.14603e-08, 0, -0.5, 0, 0.5, 0, 0.5, 0, -8.14603e-08, 1.10362, 1.60047, -0.25993 )
visible = false
song_name = "VRWorkout Theme"
level_number = 0

[node name="Level3" parent="." instance=ExtResource( 6 )]
transform = Transform( -8.14603e-08, 0, -0.5, 0, 0.5, 0, 0.5, 0, -8.14603e-08, 1.10362, 1.40346, -0.25993 )
visible = false
song_name = "Like This"
level_number = 2

[node name="Level5" parent="." instance=ExtResource( 6 )]
transform = Transform( -8.14603e-08, 0, -0.5, 0, 0.5, 0, 0.5, 0, -8.14603e-08, 1.1033, 1.20408, -0.26 )
visible = false
song_name = "Shameless promotion"
level_number = 4

[node name="Level2" parent="." instance=ExtResource( 6 )]
transform = Transform( -8.14603e-08, 0, -0.5, 0, 0.5, 0, 0.5, 0, -8.14603e-08, 1.10362, 1.60047, 0.424775 )
visible = false
song_name = "Deeper in yourself"
level_number = 1

[node name="Level4" parent="." instance=ExtResource( 6 )]
transform = Transform( -8.14603e-08, 0, -0.5, 0, 0.5, 0, 0.5, 0, -8.14603e-08, 1.103, 1.403, 0.425 )
visible = false
song_name = "The game has changed"
level_number = 3

[node name="Level6" parent="." instance=ExtResource( 6 )]
transform = Transform( -8.14603e-08, 0, -0.5, 0, 0.5, 0, 0.5, 0, -8.14603e-08, 1.103, 1.204, 0.425 )
visible = false
song_name = "Scomber clarity"
level_number = 5

[node name="Freeplay1" parent="." instance=ExtResource( 6 )]
transform = Transform( -0.5, 0, 1.03316e-07, 0, 0.5, 0, -1.03316e-07, 0, -0.5, 0.0179138, 1.6, 1.01773 )
song_name = "Freeplay 1 hour"
Expand Down Expand Up @@ -249,7 +213,7 @@ ontext = "Knee saver on"
offtext = "Knee saver off"

[node name="YogaSwitch" parent="." instance=ExtResource( 3 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.324, -0.992, -0.92 )
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.324, 0.992, -0.92 )
value = true
ontext = "Warmup on"
offtext = "Warmup off"
Expand Down
45 changes: 30 additions & 15 deletions godot_project/Main.gd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
extends Spatial


signal level_finished
var gu = GameUtilities.new()

var song_index_parameter = 0
var audio_filename = ""
Expand Down Expand Up @@ -122,8 +122,9 @@ func setup_cue_parameters(difficulty, player_height):
"yrange": 0.1
},
CueSelector.HAND : {
"rotation_range": difficulty*35, #increase core rotation with difficulty
"xrange" : 0.1,
"xspread" : 0.2,
"xspread" : max(0.1, 0.2 - difficulty/10.0), #If core rotation increases, decrease spread
"yoffset" : player_height * 0.526 + difficulty * player_height/20.0,
"yrange" : 0.2
}
Expand Down Expand Up @@ -241,7 +242,10 @@ var update_counter = 0
func update_info(hits, max_hits, points):
var song_pos = int(cue_emitter.current_playback_time)
var total = int(stream.stream.get_length())
infolayer.print_info("Hits %d/%d - Song: %d/%.1f%% - Points: %d - Speed: %.1f"% [hits,max_hits,song_pos,float(100*song_pos)/total,points,running_speed])

var elapsed_string = gu.seconds_to_timestring(song_pos)

infolayer.print_info("Hits %d/%d - Song: %s (%.1f%%) - Points: %d - Speed: %.1f"% [hits,max_hits,elapsed_string,float(100*song_pos)/total,points,running_speed])
if update_counter % 5 == 0:
infolayer.print_info("Player height: %.2f Difficulty: %.1f/%.2f/%.2f"%[player_height, current_difficulty, min_cue_space, min_state_duration], "debug")
update_counter += 1
Expand Down Expand Up @@ -314,10 +318,8 @@ func _ready():

groove_display = get_node("GrooveDisplay")

update_cue_timing()

beat_index = 0

current_difficulty = GameVariables.difficulty
setup_difficulty(current_difficulty)

beats = []
Expand Down Expand Up @@ -379,8 +381,7 @@ func _ready():
beats.append(pos)
pos += delta


if stream:
if stream.stream:
stream.play()

update_safe_pushup()
Expand All @@ -403,7 +404,11 @@ func setup_difficulty(diff):
min_cue_space = level_min_cue_space
min_state_duration = level_min_state_duration
current_difficulty = d

update_cue_timing()

setup_cue_parameters(d, player_height)


var last_playback_time = 0
func _process(delta):
Expand Down Expand Up @@ -483,7 +488,7 @@ func create_and_attach_cue(cue_type, x, y, target_time, fly_offset=0, fly_time =
cue_node.extended = true
if cue_type in ["right_hold", "left_hold"]:
cue_node.is_hold_cue = true
cue_node.hold_time = 1.0
cue_node.hold_time = 0.5
cue_node.target_time = target_time
cue_node.start_time = cue_emitter.current_playback_time
var actual_flytime = fly_time
Expand All @@ -506,7 +511,6 @@ func create_and_attach_cue(cue_type, x, y, target_time, fly_offset=0, fly_time =
if cue_type in ["left", "right", "left_hold", "right_hold"]:
var alpha = atan2(x,y-head_y_pos)
cue_node.set_transform(cue_node.get_transform().rotated(Vector3(0,0,1),-alpha))


move_modifier.interpolate_property(cue_node,"translation",Vector3(x,y,0+fly_offset),Vector3(x,y,fly_distance+fly_offset),actual_flytime,Tween.TRANS_LINEAR,Tween.EASE_IN_OUT,0)
move_modifier.connect("tween_completed",self,"_on_tween_completed")
Expand Down Expand Up @@ -641,9 +645,9 @@ func handle_yoga_cues(target_time):
yoga_state = state_transition(yoga_state, yoga_state_model)

if yoga_state == YogaState.LEFT:
create_and_attach_cue("left_hold", -0.3*player_height, 0.85 * player_height, target_time, 0)
create_and_attach_cue("left_hold", -0.3*player_height, 0.85 * player_height, target_time, 0, target_time+0.5)
else:
create_and_attach_cue("right_hold", 0.3*player_height, 0.85 * player_height, target_time, 0)
create_and_attach_cue("right_hold", 0.3*player_height, 0.85 * player_height, target_time, 0, target_time+0.5)

func handle_stand_cues(target_time):
switch_floor_sign("feet")
Expand Down Expand Up @@ -770,20 +774,29 @@ func handle_crunch_cues(target_time):

var node_selector = rng.randi()%100

var rot = (rng.randf()-0.5) * deg2rad(cue_parameters[cue_emitter_state][CueSelector.HAND]["rotation_range"])

var x_head = rng.randf() * cue_parameters[cue_emitter_state][CueSelector.HEAD]["xrange"] - cue_parameters[cue_emitter_state][CueSelector.HEAD]["xrange"]/2
var y_head = cue_parameters[cue_emitter_state][CueSelector.HEAD]["yoffset"] + rng.randf() * cue_parameters[cue_emitter_state][CueSelector.HEAD]["yrange"]
var y_hand = cue_parameters[cue_emitter_state][CueSelector.HAND]["yoffset"] + rng.randf() * cue_parameters[cue_emitter_state][CueSelector.HAND]["yrange"]

var rot_distance_reduction = max(0.4, 1.0 - (1.5 * abs(rot)/PI))
var y_hand = rot_distance_reduction * cue_parameters[cue_emitter_state][CueSelector.HAND]["yoffset"] + rng.randf() * cue_parameters[cue_emitter_state][CueSelector.HAND]["yrange"]
var x = rng.randf() * cue_parameters[cue_emitter_state][CueSelector.HAND]["xrange"] - cue_parameters[cue_emitter_state][CueSelector.HAND]["xrange"]/2

print ("Crunch Spread %.2f"%(cue_parameters[cue_emitter_state][CueSelector.HAND]["xspread"]))

if cue_selector == CueSelector.HAND and node_selector < 80:
cue_selector = CueSelector.HEAD
elif cue_selector == CueSelector.HEAD and node_selector < 80:
cue_selector = CueSelector.HAND

if cue_selector == CueSelector.HAND:
var spread = cue_parameters[cue_emitter_state][CueSelector.HAND]["xspread"]/2.0+rng.randf()*cue_parameters[cue_emitter_state][CueSelector.HAND]["xspread"]
create_and_attach_cue("right", x+spread,y_hand, target_time)
create_and_attach_cue("left", x-spread,y_hand, target_time)
var t = Transform(Vector3(1,0,0), Vector3(0,1,0), Vector3(0,0,1), Vector3(0,0,0)).rotated(Vector3(0,0,1), rot)
var tmp = t.xform(Vector3(x+spread,y_hand,0))
create_and_attach_cue("right", tmp.x, tmp.y, target_time)
tmp = t.xform(Vector3(x-spread,y_hand,0))
create_and_attach_cue("left", tmp.x,tmp.y, target_time)
else:
create_and_attach_cue("head", x_head, y_head, target_time)

Expand Down Expand Up @@ -843,6 +856,8 @@ func handle_pushup_cues(target_time):
create_and_attach_cue("left", x, y_hand, target_time + hand_delay, -hand_delay * dd_df)
temporary_cue_space_extension = 2.5



func internal_state_change():
state_changed = true
last_state_change = cue_emitter.current_playback_time
Expand Down
Loading

0 comments on commit 83fb136

Please sign in to comment.