This commit is contained in:
Dooho Yi 2023-10-07 18:29:52 +09:00
parent 3fc766e6ae
commit f6a25adc83
30 changed files with 770 additions and 29 deletions

6
Events.tscn Normal file
View file

@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://Events.gd" type="Script" id=1]
[node name="Events" type="Node"]
script = ExtResource( 1 )

View file

@ -3,7 +3,7 @@ extends Node
#scene changing #scene changing
var _scenelist = ["res://Main.tscn", "res://oscScene.tscn"] var _scenelist = ["res://mainScene/Main.tscn", "res://oscScene/oscScene.tscn"]
var _sceneidx = 0 var _sceneidx = 0
func nextScene(): func nextScene():

View file

@ -1,6 +0,0 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://PlayerInfo.gd" type="Script" id=1]
[node name="PlayerInfo" type="Node"]
script = ExtResource( 1 )

View file

@ -0,0 +1,8 @@
[gd_resource type="NativeScript" load_steps=2 format=2]
[ext_resource path="res://addons/gdpd/bin/libgdpd.gdnlib" type="GDNativeLibrary" id=1]
[resource]
resource_name = "gdpd"
class_name = "Gdpd"
library = ExtResource( 1 )

View file

@ -0,0 +1,18 @@
[general]
singleton=false
load_once=false
symbol_prefix="godot_"
reloadable=true
[entry]
X11.64="res://addons/gdpd/bin/x11/libgdpd.so"
Windows.64="res://addons/gdpd/bin/win/libgdpd.dll"
OSX.64="res://addons/gdpd/bin/osx/libgdpd.dylib"
[dependencies]
X11.64=[ ]
Windows.64=[ ]
OSX.64=[ ]

Binary file not shown.

View file

@ -0,0 +1,8 @@
[gd_resource type="NativeScript" load_steps=2 format=2]
[ext_resource path="res://addons/gdpd/bin/libgdpd.gdnlib" type="GDNativeLibrary" id=1]
[resource]
resource_name = "gdpd"
class_name = "Gdpd"
library = ExtResource( 1 )

View file

@ -0,0 +1,18 @@
[general]
singleton=false
load_once=false
symbol_prefix="godot_"
reloadable=true
[entry]
X11.64="res://addons/gdpd/bin/x11/libgdpd.so"
Windows.64="res://addons/gdpd/bin/win/libgdpd.dll"
OSX.64="res://addons/gdpd/bin/osx/libgdpd.dylib"
[dependencies]
X11.64=[ ]
Windows.64=[ ]
OSX.64=[ ]

Binary file not shown.

Binary file not shown.

View file

@ -27,7 +27,7 @@ func _physics_process(delta):
# emit signal - playerinfo_updated # emit signal - playerinfo_updated
var tf = $Head/Camera.get_global_transform_interpolated() var tf = $Head/Camera.get_global_transform_interpolated()
if tf != _oldtf: if tf != _oldtf:
PlayerInfo.emit_signal("player_transform_updated", $Head/Camera.get_global_translation(), $Head.global_rotation.y) Events.emit_signal("player_transform_updated", $Head/Camera.get_global_translation(), $Head.global_rotation.y)
_oldtf = tf _oldtf = tf
if Input.is_action_just_pressed('toggle_mouse'): if Input.is_action_just_pressed('toggle_mouse'):

21
cricketScene/Player.tscn Normal file
View file

@ -0,0 +1,21 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://cricketScene/Player.gd" type="Script" id=1]
[sub_resource type="CapsuleShape" id=1]
radius = 0.6
height = 2.0
[node name="Player" type="KinematicBody"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 3.52113, 0.98772 )
script = ExtResource( 1 )
[node name="Capsule" type="CollisionShape" parent="."]
transform = Transform( 1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0 )
shape = SubResource( 1 )
[node name="Head" type="Spatial" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.5, 0 )
[node name="Camera" type="Camera" parent="Head"]
far = 10000.0

82
cricketScene/Scene.gd Normal file
View file

@ -0,0 +1,82 @@
extends Node
var crickettscn = load("res://cricketScene/cricket.tscn")
var preset_grpA = [
[-7, -2, 3996, 30, 0.7],
[-7, -2, 3896, 30, 0.5],
[-7, -2, 3596, 30, 0.5],
[-7, -2, 3606, 60, 0.9]
]
var preset_grpB = [
[1, 7, 11086, 30, 0.5],
[1, 7, 10086, 340, 0.5],
[1, 7, 11486, 390, 0.5],
[1, 7, 12086, 400, 0.5]
]
var preset_grpC = [
[1, -9, 19, 10, 0.5],
[5, -9, 11, -10, 0.5],
[3, -10, 7, 20, 0.5],
[6, -9, 9, 10, 0.5]
]
var preset_grpD = [
[-7, -2343, -1550, 30, 0.4],
[-8, -2233, -1481, 10, 0.5],
[-7, -2483, -1531, 30, 0.4],
[-7, -2281, -1581, 10, 0.7]
]
var preset_grps = [
preset_grpA,
preset_grpB,
preset_grpC,
preset_grpD
]
var preset_colors = [
Color.greenyellow,
Color.deeppink,
Color.lavender,
Color.aqua
]
func _ready():
randomize()
for i in range(8):
var cricket = crickettscn.instance()
cricket.set_param(preset_grps[0][randi()%4])
cricket.set_color(preset_colors[0])
cricket.audible_range_max = 20
add_child(cricket)
cricket.relocate(Vector2(20, 20), [4, 8])
for i in range(8):
var cricket = crickettscn.instance()
cricket.set_param(preset_grps[1][randi()%4])
cricket.set_color(preset_colors[1])
cricket.audible_range_max = 20
add_child(cricket)
cricket.relocate(Vector2(-20, 20), [4, 8])
for i in range(8):
var cricket = crickettscn.instance()
cricket.set_param(preset_grps[2][randi()%4])
cricket.set_color(preset_colors[2])
cricket.audible_range_max = 20
add_child(cricket)
cricket.relocate(Vector2(-20, -20), [4, 8])
for i in range(8):
var cricket = crickettscn.instance()
cricket.set_param(preset_grps[3][randi()%4])
cricket.set_color(preset_colors[3])
cricket.audible_range_max = 20
add_child(cricket)
cricket.relocate(Vector2(20, -20), [4, 8])
func _on_Timer_timeout():
Global.nextScene()

40
cricketScene/Scene.tscn Normal file
View file

@ -0,0 +1,40 @@
[gd_scene load_steps=6 format=2]
[ext_resource path="res://cricketScene/Scene.gd" type="Script" id=1]
[ext_resource path="res://cricketScene/Player.tscn" type="PackedScene" id=2]
[sub_resource type="BoxShape" id=1]
extents = Vector3( 30, 1, 30 )
[sub_resource type="CubeMesh" id=2]
size = Vector3( 60, 2, 60 )
[sub_resource type="Environment" id=3]
fog_enabled = true
[node name="Scene" type="Node"]
script = ExtResource( 1 )
[node name="StaticBody" type="StaticBody" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1, 0 )
[node name="CollisionShape" type="CollisionShape" parent="StaticBody"]
shape = SubResource( 1 )
[node name="MeshInstance" type="MeshInstance" parent="StaticBody"]
mesh = SubResource( 2 )
[node name="DirectionalLight" type="DirectionalLight" parent="."]
transform = Transform( 1, 0, 0, 0, 0.158589, 0.987345, 0, -0.987345, 0.158589, 0, 57.3999, 0 )
shadow_enabled = true
[node name="Player" parent="." instance=ExtResource( 2 )]
[node name="Timer" type="Timer" parent="."]
wait_time = 2.0
one_shot = true
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource( 3 )
[connection signal="timeout" from="Timer" to="." method="_on_Timer_timeout"]

View file

@ -0,0 +1,273 @@
#N canvas 0 82 446 513 12;
#X obj 21 22 r fromGodot\$0;
#X obj 21 46 list trim;
#X obj 303 253 hsl 100 20 -1 1 0 0 empty empty empty -2 -10 0 12 -262144
-1 -1 6100 1;
#X obj 300 349 line~;
#X msg 300 325 \$1 100;
#X obj 300 278 expr ($f1 + 1)/8;
#X floatatom 300 302 5 0 0 0 - - -;
#N canvas 68 97 450 300 pan2~ 0;
#X obj 51 98 cos~;
#X obj 111 98 cos~;
#X obj 33 128 *~;
#X obj 93 128 *~;
#X obj 33 158 outlet~;
#X obj 93 158 outlet~;
#X obj 33 24 inlet~;
#X obj 111 24 inlet~;
#X obj 111 74 +~ 0.75;
#X connect 0 0 2 1;
#X connect 1 0 3 1;
#X connect 2 0 4 0;
#X connect 3 0 5 0;
#X connect 6 0 2 0;
#X connect 6 0 3 0;
#X connect 7 0 8 0;
#X connect 7 0 0 0;
#X connect 8 0 1 0;
#X restore 199 437 pd pan2~;
#X obj 199 467 dac~ 1 2;
#X obj 199 407 *~;
#X obj 189 230 line~;
#X msg 189 206 \$1 100;
#X obj 189 127 unpack f f;
#X floatatom 296 159 5 0 0 0 - - -;
#X obj 296 182 sin;
#X floatatom 296 206 5 0 0 0 - - -;
#X floatatom 189 177 5 0 0 0 - - -;
#X obj 21 70 route bang panvol param;
#N canvas 197 23 913 799 synth 0;
#X obj 334 43 inlet;
#X obj 254 630 +~ 1;
#X obj 254 658 *~ 50;
#X obj 571 656 *~;
#X obj 95 350 metro 0.5 120 permin;
#X obj 95 380 bng 16 250 50 0 empty empty empty 0 -12 0 16 -262144
-1 -1;
#X obj 21 192 tgl 24 0 empty empty empty 0 -12 0 16 -262144 -1 -1 1
1;
#X msg 95 310 tempo \$1 permin;
#X floatatom 95 281 5 0 0 1 bpm - -;
#X obj 95 407 f;
#X obj 141 407 + 1;
#X floatatom 95 437 5 0 0 0 - - -;
#X obj 95 526 bng 16 250 50 0 empty empty empty 0 -16 0 24 -262144
-1 -1;
#X obj 122 526 bng 16 250 50 0 empty empty empty 0 -16 0 24 -262144
-1 -1;
#X obj 149 526 bng 16 250 50 0 empty empty empty 0 -16 0 24 -262144
-1 -1;
#X floatatom 95 563 5 0 0 0 - - -;
#X obj 95 602 sel 0;
#X obj 127 632 mtof;
#X obj 127 750 line~;
#X msg 127 721 \$1 \$2;
#X obj 127 694 pack;
#X floatatom 127 668 5 0 0 0 - - -;
#X floatatom 171 606 5 0 0 1 ramp - -;
#X floatatom 458 475 5 0 0 1 AM - -;
#X obj 404 594 expr~ ($v1+1)/2;
#X obj 404 622 expr~ 1-$v1;
#X obj 404 649 *~;
#X floatatom 275 476 5 0 3 1 VolAM - -;
#X obj 386 759 *~;
#X obj 404 561 osc~;
#X obj 254 605 osc~ 440;
#X obj 275 452 line;
#X msg 95 243 10;
#X msg 133 244 20;
#X msg 170 243 30;
#X msg 210 243 40;
#X obj 275 315 random 3;
#X obj 275 339 sel 0 1 2;
#X obj 95 171 random 4;
#X obj 95 209 sel 0 1 2 3;
#X obj 95 111 tgl 19 0 empty empty empty 0 -10 0 12 -262144 -1 -1 1
1;
#X obj 95 140 metro 3000;
#X msg 238 513 1 200;
#X msg 275 367 0 1000;
#X msg 295 391 0 1400;
#X msg 315 415 0 1800;
#X obj 180 526 bng 16 250 50 0 empty empty empty 0 -16 0 24 -262144
-1 -1;
#X floatatom 200 563 5 0 0 0 - - -;
#X obj 95 496 sel 0 1 2 3 4 5;
#X obj 95 466 mod 6;
#X obj 430 225 osc~;
#X obj 430 253 +~ 1;
#X obj 430 309 snapshot~;
#X obj 504 266 metro 100;
#X obj 506 231 tgl 20 0 empty empty empty 0 -16 0 24 -262144 -1 -1
1 1;
#X obj 433 338 hsl 100 18 0 300 0 0 empty empty empty -2 -16 0 24 -262144
-1 -1 9900 1;
#X floatatom 430 367 5 0 0 0 - - -;
#X floatatom 404 537 5 0 0 0 - - -;
#X obj 404 513 +;
#X obj 430 279 *~ 150;
#X obj 20 136 loadbang;
#X msg 21 159 1;
#X obj 95 11 loadbang;
#X msg 95 51 1;
#X obj 507 170 loadbang;
#X msg 508 193 1;
#X floatatom 388 117 5 0 0 0 - - -;
#X floatatom 430 117 5 0 0 0 - - -;
#X floatatom 305 117 5 0 0 0 - - -;
#X floatatom 347 117 5 0 0 0 - - -;
#X obj 334 74 unpack f f f f f;
#X floatatom 589 117 5 0 0 0 - - -;
#X obj 206 40 tgl 19 0 empty empty empty 0 -10 0 12 -262144 -1 -1 1
1;
#X obj 206 88 t b b;
#X obj 341 225 +;
#X floatatom 341 249 5 0 0 0 - - -;
#X obj 206 136 * 10;
#X obj 206 112 random 4;
#X obj 206 64 metro 3000;
#X obj 571 680 outlet~;
#X obj 254 691 tabread~ \$0-shaping;
#N canvas 0 22 450 278 (subpatch) 0;
#X array \$0-shaping 100 float 1;
#A 0 0.159999 0.159999 0.159999 0.159999 0.159999 0.159999 0.159999
0.159999 0.159999 0.15 0.14 0.14 0.13 0.12 0.110001 0.110001 0.110001
0.100001 0.100001 0.100001 0.100001 0.100001 0.0900012 0.0900012 0.0900012
0.0800015 0.060002 0.0500022 7.15256e-07 -0.0399983 -0.0599978 -0.0899971
-0.119996 -0.134996 -0.159995 -0.189995 -0.209994 -0.229994 -0.249993
-0.269993 -0.299992 -0.339991 -0.35999 -0.38999 -0.429989 -0.479987
-0.509987 -0.519986 -0.489987 -0.459988 -0.439988 -0.419989 -0.37999
-0.329991 -0.299992 -0.269993 -0.249993 -0.219994 -0.199994 -0.179995
-0.169995 -0.159995 -0.129996 -0.109997 -0.0799973 -0.0699975 -0.049998
-0.0399983 -0.0199988 7.15256e-07 0.0100005 0.0200002 0.03 0.03 0.03
0.0399997 0.0399997 0.0399997 0.0399997 0.0399997 0.0399997 0.0399997
0.0399997 0.0399997 0.0399997 0.0399997 0.0399997 0.0399997 0.0399997
0.0399997 0.0399997 0.03 0.03 0.0200002 0.0100005 0.0100005 7.15256e-07
-0.00999904 -0.00999904 -0.00999904;
#X coords 0 -1 100 1 200 200 1 0 0;
#X restore 676 38 graph;
#X connect 0 0 70 0;
#X connect 1 0 2 0;
#X connect 2 0 80 0;
#X connect 3 0 79 0;
#X connect 4 0 5 0;
#X connect 5 0 9 0;
#X connect 6 0 4 0;
#X connect 7 0 4 0;
#X connect 8 0 7 0;
#X connect 9 0 10 0;
#X connect 9 0 11 0;
#X connect 10 0 9 1;
#X connect 11 0 49 0;
#X connect 12 0 15 0;
#X connect 13 0 36 0;
#X connect 15 0 16 0;
#X connect 16 1 17 0;
#X connect 17 0 21 0;
#X connect 18 0 30 0;
#X connect 19 0 18 0;
#X connect 20 0 19 0;
#X connect 21 0 20 0;
#X connect 22 0 20 1;
#X connect 23 0 58 1;
#X connect 24 0 25 0;
#X connect 25 0 26 0;
#X connect 26 0 28 1;
#X connect 27 0 26 1;
#X connect 28 0 3 0;
#X connect 29 0 24 0;
#X connect 30 0 1 0;
#X connect 31 0 27 0;
#X connect 32 0 8 0;
#X connect 33 0 8 0;
#X connect 34 0 8 0;
#X connect 35 0 8 0;
#X connect 36 0 37 0;
#X connect 37 0 43 0;
#X connect 37 1 44 0;
#X connect 37 2 45 0;
#X connect 38 0 39 0;
#X connect 39 0 32 0;
#X connect 39 1 33 0;
#X connect 39 2 34 0;
#X connect 39 3 35 0;
#X connect 40 0 41 0;
#X connect 41 0 38 0;
#X connect 42 0 31 0;
#X connect 43 0 31 0;
#X connect 44 0 31 0;
#X connect 45 0 31 0;
#X connect 46 0 47 0;
#X connect 46 0 42 0;
#X connect 47 0 16 0;
#X connect 48 0 12 0;
#X connect 48 1 13 0;
#X connect 48 2 14 0;
#X connect 48 5 46 0;
#X connect 49 0 48 0;
#X connect 50 0 51 0;
#X connect 51 0 59 0;
#X connect 52 0 55 0;
#X connect 53 0 52 0;
#X connect 54 0 53 0;
#X connect 55 0 56 0;
#X connect 56 0 58 0;
#X connect 57 0 29 0;
#X connect 58 0 57 0;
#X connect 59 0 52 0;
#X connect 60 0 61 0;
#X connect 61 0 6 0;
#X connect 62 0 63 0;
#X connect 62 0 72 0;
#X connect 63 0 40 0;
#X connect 64 0 65 0;
#X connect 65 0 54 0;
#X connect 66 0 58 1;
#X connect 66 0 74 0;
#X connect 67 0 50 0;
#X connect 68 0 15 0;
#X connect 69 0 47 0;
#X connect 70 0 68 0;
#X connect 70 1 69 0;
#X connect 70 2 66 0;
#X connect 70 3 67 0;
#X connect 70 4 71 0;
#X connect 71 0 3 1;
#X connect 72 0 78 0;
#X connect 73 0 77 0;
#X connect 73 1 66 0;
#X connect 74 0 75 0;
#X connect 75 0 58 1;
#X connect 76 0 74 1;
#X connect 77 0 76 0;
#X connect 78 0 73 0;
#X connect 80 0 28 0;
#X restore 80 300 pd synth;
#X obj 21 120 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
-1;
#X obj 361 21 loadbang;
#X msg 361 51 \; pd dsp 1;
#X connect 0 0 1 0;
#X connect 1 0 17 0;
#X connect 2 0 5 0;
#X connect 3 0 7 1;
#X connect 4 0 3 0;
#X connect 5 0 6 0;
#X connect 6 0 4 0;
#X connect 7 0 8 0;
#X connect 7 1 8 1;
#X connect 9 0 7 0;
#X connect 10 0 9 1;
#X connect 11 0 10 0;
#X connect 12 0 16 0;
#X connect 12 1 13 0;
#X connect 13 0 14 0;
#X connect 14 0 15 0;
#X connect 15 0 2 0;
#X connect 16 0 11 0;
#X connect 17 0 19 0;
#X connect 17 1 12 0;
#X connect 17 2 18 0;
#X connect 18 0 9 0;
#X connect 20 0 21 0;

61
cricketScene/cricket.gd Normal file
View file

@ -0,0 +1,61 @@
extends RigidBody
var _my_patch = "res://cricketScene/cricket-node.pd"
var _my_id = 0
export (float, 0, 100) var audible_range_max = 10.0
export (Array, float) var parameters = [-7, -2, 3996, 30, 0.7]
func set_param(param):
parameters = param
func set_color(color):
$MeshInstance.material_override = SpatialMaterial.new()
$MeshInstance.material_override.albedo_color = color
func relocate(center, radius_range):
# relocate randomly into a circular zone
var rr = radius_range[1] - radius_range[0]
var displacement = polar2cartesian(randf()*rr+radius_range[0], randf()*2*PI)
var loc = center + displacement
look_at_from_position(Vector3(loc.x, randf()*2 + 1, loc.y), Vector3.FORWARD, Vector3.UP)
func _ready():
# load patch
_my_id = Global.load_patch(ProjectSettings.globalize_path(_my_patch))
# listen 'player_transform_updated' event
Events.connect("player_transform_updated", self, "_on_Events_player_transform_updated")
# send to the patch
Global._gdpd.start_message(6)
Global._gdpd.add_symbol("param")
Global._gdpd.add_float(parameters[0])
Global._gdpd.add_float(parameters[1])
Global._gdpd.add_float(parameters[2])
Global._gdpd.add_float(parameters[3])
Global._gdpd.add_float(parameters[4])
Global._gdpd.finish_list("fromGodot" + String(_my_id))
func _on_Events_player_transform_updated(playerpos, playerheading):
var mypos = get_global_translation()
var mypos2d = Vector2(mypos.x, mypos.z)
var playerpos2d = Vector2(playerpos.x, playerpos.z)
# calculate distance
var distance = mypos.distance_to(playerpos)
# calculate angle
var angle = fmod(fmod(playerpos2d.angle_to_point(mypos2d) + playerheading - PI/2, PI*2) + PI*2, PI*2)
if angle > PI:
angle = angle - PI*2
# calculate gain
var gain = max(1 - distance/audible_range_max, 0)
# send to the patch
Global._gdpd.start_message(3)
Global._gdpd.add_symbol("panvol")
Global._gdpd.add_float(gain)
Global._gdpd.add_float(angle)
Global._gdpd.finish_list("fromGodot" + String(_my_id))
func _exit_tree():
Global.close_patch(_my_id)
pass

25
cricketScene/cricket.tscn Normal file
View file

@ -0,0 +1,25 @@
[gd_scene load_steps=6 format=2]
[ext_resource path="res://cricketScene/cricket.gd" type="Script" id=1]
[sub_resource type="PhysicsMaterial" id=3]
[sub_resource type="SphereShape" id=1]
[sub_resource type="SpatialMaterial" id=4]
[sub_resource type="SphereMesh" id=2]
material = SubResource( 4 )
[node name="cricket" type="RigidBody" groups=["sounders"]]
collision_layer = 4
collision_mask = 0
physics_material_override = SubResource( 3 )
gravity_scale = 0.0
script = ExtResource( 1 )
[node name="CollisionShape" type="CollisionShape" parent="."]
shape = SubResource( 1 )
[node name="MeshInstance" type="MeshInstance" parent="."]
mesh = SubResource( 2 )

View file

@ -1,7 +1,7 @@
[gd_scene load_steps=6 format=2] [gd_scene load_steps=6 format=2]
[ext_resource path="res://Player.tscn" type="PackedScene" id=1] [ext_resource path="res://mainScene/Main.gd" type="Script" id=1]
[ext_resource path="res://Main.gd" type="Script" id=2] [ext_resource path="res://mainScene/Player.tscn" type="PackedScene" id=2]
[sub_resource type="BoxShape" id=1] [sub_resource type="BoxShape" id=1]
extents = Vector3( 30, 1, 30 ) extents = Vector3( 30, 1, 30 )
@ -17,7 +17,7 @@ material = SubResource( 3 )
size = Vector3( 60, 2, 60 ) size = Vector3( 60, 2, 60 )
[node name="Main" type="Node"] [node name="Main" type="Node"]
script = ExtResource( 2 ) script = ExtResource( 1 )
[node name="StaticBody" type="StaticBody" parent="."] [node name="StaticBody" type="StaticBody" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1, 0 ) transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1, 0 )
@ -36,13 +36,11 @@ mesh = SubResource( 2 )
transform = Transform( 1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 60, 0 ) transform = Transform( 1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 60, 0 )
shadow_enabled = true shadow_enabled = true
[node name="Player" parent="." instance=ExtResource( 1 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2.5, 0 )
collision_layer = 2
[node name="Timer" type="Timer" parent="."] [node name="Timer" type="Timer" parent="."]
wait_time = 2.0 wait_time = 2.0
one_shot = true one_shot = true
autostart = true autostart = true
[node name="Player" parent="." instance=ExtResource( 2 )]
[connection signal="timeout" from="Timer" to="." method="_on_Timer_timeout"] [connection signal="timeout" from="Timer" to="." method="_on_Timer_timeout"]

81
mainScene/Player.gd Normal file
View file

@ -0,0 +1,81 @@
extends KinematicBody
var camera_angle = 0
var mouse_sensitivity = 0.3
var camera_change = Vector2()
var velocity = Vector3()
var direction = Vector3()
var _oldtf = Transform()
#fly variables
const FLY_SPEED = 20
const FLY_ACCEL = 4
var mouse_captured = true
func _ready():
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
func _physics_process(delta):
if mouse_captured:
aim()
fly(delta)
# emit signal - playerinfo_updated
var tf = $Head/Camera.get_global_transform_interpolated()
if tf != _oldtf:
Events.emit_signal("player_transform_updated", $Head/Camera.get_global_translation(), $Head.global_rotation.y)
_oldtf = tf
if Input.is_action_just_pressed('toggle_mouse'):
if mouse_captured:
mouse_captured = false
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
else:
mouse_captured = true
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
func _input(event):
if event is InputEventMouseMotion:
camera_change = event.relative
func fly(delta):
# reset the direction of the player
direction = Vector3()
# get the rotation of the camera
var aim = $Head/Camera.get_global_transform().basis
# check input and change direction
if Input.is_action_pressed("move_forward"):
direction -= aim.z
if Input.is_action_pressed("move_backward"):
direction += aim.z
if Input.is_action_pressed("move_left"):
direction -= aim.x
if Input.is_action_pressed("move_right"):
direction += aim.x
direction = direction.normalized()
# where would the player go at max speed
var target = direction * FLY_SPEED
# calculate a portion of the distance to go
velocity = velocity.linear_interpolate(target, FLY_ACCEL * delta)
# move
move_and_slide(velocity)
func aim():
if camera_change.length() > 0:
$Head.rotate_y(deg2rad(-camera_change.x * mouse_sensitivity))
var change = -camera_change.y * mouse_sensitivity
if change + camera_angle < 90 and change + camera_angle > -90:
$Head/Camera.rotate_x(deg2rad(change))
camera_angle += change
camera_change = Vector2()

View file

@ -1,6 +1,6 @@
[gd_scene load_steps=3 format=2] [gd_scene load_steps=3 format=2]
[ext_resource path="res://Player.gd" type="Script" id=1] [ext_resource path="res://oscScene/Player.gd" type="Script" id=1]
[sub_resource type="CapsuleShape" id=1] [sub_resource type="CapsuleShape" id=1]
radius = 0.6 radius = 0.6

81
oscScene/Player.gd Normal file
View file

@ -0,0 +1,81 @@
extends KinematicBody
var camera_angle = 0
var mouse_sensitivity = 0.3
var camera_change = Vector2()
var velocity = Vector3()
var direction = Vector3()
var _oldtf = Transform()
#fly variables
const FLY_SPEED = 20
const FLY_ACCEL = 4
var mouse_captured = true
func _ready():
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
func _physics_process(delta):
if mouse_captured:
aim()
fly(delta)
# emit signal - playerinfo_updated
var tf = $Head/Camera.get_global_transform_interpolated()
if tf != _oldtf:
Events.emit_signal("player_transform_updated", $Head/Camera.get_global_translation(), $Head.global_rotation.y)
_oldtf = tf
if Input.is_action_just_pressed('toggle_mouse'):
if mouse_captured:
mouse_captured = false
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
else:
mouse_captured = true
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
func _input(event):
if event is InputEventMouseMotion:
camera_change = event.relative
func fly(delta):
# reset the direction of the player
direction = Vector3()
# get the rotation of the camera
var aim = $Head/Camera.get_global_transform().basis
# check input and change direction
if Input.is_action_pressed("move_forward"):
direction -= aim.z
if Input.is_action_pressed("move_backward"):
direction += aim.z
if Input.is_action_pressed("move_left"):
direction -= aim.x
if Input.is_action_pressed("move_right"):
direction += aim.x
direction = direction.normalized()
# where would the player go at max speed
var target = direction * FLY_SPEED
# calculate a portion of the distance to go
velocity = velocity.linear_interpolate(target, FLY_ACCEL * delta)
# move
move_and_slide(velocity)
func aim():
if camera_change.length() > 0:
$Head.rotate_y(deg2rad(-camera_change.x * mouse_sensitivity))
var change = -camera_change.y * mouse_sensitivity
if change + camera_angle < 90 and change + camera_angle > -90:
$Head/Camera.rotate_x(deg2rad(change))
camera_angle += change
camera_change = Vector2()

21
oscScene/Player.tscn Normal file
View file

@ -0,0 +1,21 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://oscScene/Player.gd" type="Script" id=1]
[sub_resource type="CapsuleShape" id=1]
radius = 0.6
height = 2.0
[node name="Player" type="KinematicBody"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 3.52113, 0.98772 )
script = ExtResource( 1 )
[node name="Capsule" type="CollisionShape" parent="."]
transform = Transform( 1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0 )
shape = SubResource( 1 )
[node name="Head" type="Spatial" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.5, 0 )
[node name="Camera" type="Camera" parent="Head"]
far = 10000.0

View file

@ -1,8 +1,8 @@
extends RigidBody extends RigidBody
var _my_patch = "res://osc-node.pd" var _my_patch = "res://oscScene/osc-node.pd"
var _my_id = 0 var _my_id = 0
export (float) var audible_range_max = 10 export (float, 0, 100) var audible_range_max = 10.0
func _ready(): func _ready():
# load patch # load patch
@ -17,10 +17,9 @@ func _ready():
Global._gdpd.finish_list("fromGodot" + String(_my_id)) # send msg. individually ($0) Global._gdpd.finish_list("fromGodot" + String(_my_id)) # send msg. individually ($0)
# listen 'player_transform_updated' event # listen 'player_transform_updated' event
PlayerInfo.connect("player_transform_updated", self, "_on_PlayerInfo_player_transform_updated") Events.connect("player_transform_updated", self, "_on_Events_player_transform_updated")
func _on_Events_player_transform_updated(playerpos, playerheading):
func _on_PlayerInfo_player_transform_updated(playerpos, playerheading):
var mypos = get_global_translation() var mypos = get_global_translation()
var mypos2d = Vector2(mypos.x, mypos.z) var mypos2d = Vector2(mypos.x, mypos.z)
var playerpos2d = Vector2(playerpos.x, playerpos.z) var playerpos2d = Vector2(playerpos.x, playerpos.z)

View file

@ -1,6 +1,6 @@
[gd_scene load_steps=5 format=2] [gd_scene load_steps=5 format=2]
[ext_resource path="res://osc.gd" type="Script" id=1] [ext_resource path="res://oscScene/osc.gd" type="Script" id=1]
[sub_resource type="PhysicsMaterial" id=3] [sub_resource type="PhysicsMaterial" id=3]

View file

@ -1,6 +1,6 @@
extends Node extends Node
var osctscn = load("res://osc.tscn") var osctscn = load("res://oscScene/osc.tscn")
func _ready(): func _ready():
pass pass

View file

@ -1,8 +1,8 @@
[gd_scene load_steps=6 format=2] [gd_scene load_steps=7 format=2]
[ext_resource path="res://oscScene.gd" type="Script" id=1] [ext_resource path="res://oscScene/oscScene.gd" type="Script" id=1]
[ext_resource path="res://Player.tscn" type="PackedScene" id=2] [ext_resource path="res://oscScene/Player.tscn" type="PackedScene" id=2]
[ext_resource path="res://osc.tscn" type="PackedScene" id=3] [ext_resource path="res://oscScene/osc.tscn" type="PackedScene" id=3]
[sub_resource type="BoxShape" id=1] [sub_resource type="BoxShape" id=1]
extents = Vector3( 30, 1, 30 ) extents = Vector3( 30, 1, 30 )
@ -10,6 +10,9 @@ extents = Vector3( 30, 1, 30 )
[sub_resource type="CubeMesh" id=2] [sub_resource type="CubeMesh" id=2]
size = Vector3( 60, 2, 60 ) size = Vector3( 60, 2, 60 )
[sub_resource type="Environment" id=3]
fog_enabled = true
[node name="oscScene" type="Node"] [node name="oscScene" type="Node"]
script = ExtResource( 1 ) script = ExtResource( 1 )
@ -24,6 +27,7 @@ mesh = SubResource( 2 )
[node name="DirectionalLight" type="DirectionalLight" parent="."] [node name="DirectionalLight" type="DirectionalLight" parent="."]
transform = Transform( 1, 0, 0, 0, 0.158589, 0.987345, 0, -0.987345, 0.158589, 0, 57.3999, 0 ) transform = Transform( 1, 0, 0, 0, 0.158589, 0.987345, 0, -0.987345, 0.158589, 0, 57.3999, 0 )
shadow_enabled = true
[node name="Player" parent="." instance=ExtResource( 2 )] [node name="Player" parent="." instance=ExtResource( 2 )]
@ -38,4 +42,7 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -21.352, 2, 22.3 )
[node name="osc3" parent="." instance=ExtResource( 3 )] [node name="osc3" parent="." instance=ExtResource( 3 )]
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource( 3 )
[connection signal="timeout" from="Timer" to="." method="_on_Timer_timeout"] [connection signal="timeout" from="Timer" to="." method="_on_Timer_timeout"]

View file

@ -11,13 +11,13 @@ config_version=4
[application] [application]
config/name="moraepado" config/name="moraepado"
run/main_scene="res://Main.tscn" run/main_scene="res://cricketScene/Scene.tscn"
config/icon="res://icon.png" config/icon="res://icon.png"
[autoload] [autoload]
Global="*res://Global.tscn" Global="*res://Global.tscn"
PlayerInfo="*res://PlayerInfo.tscn" Events="*res://Events.tscn"
[input] [input]