diff --git a/01_prototype/.gitattributes b/01_prototype/.gitattributes new file mode 100644 index 0000000..8ad74f7 --- /dev/null +++ b/01_prototype/.gitattributes @@ -0,0 +1,2 @@ +# Normalize EOL for all files that Git considers text files. +* text=auto eol=lf diff --git a/01_prototype/.gitignore b/01_prototype/.gitignore new file mode 100644 index 0000000..4709183 --- /dev/null +++ b/01_prototype/.gitignore @@ -0,0 +1,2 @@ +# Godot 4+ specific ignores +.godot/ diff --git a/01_prototype/MagneticBallsSpawn.gd b/01_prototype/MagneticBallsSpawn.gd new file mode 100644 index 0000000..6942a04 --- /dev/null +++ b/01_prototype/MagneticBallsSpawn.gd @@ -0,0 +1,37 @@ +extends Node3D + +@export var num_balls: int = 10 +@export var force_strength: float = 10 + +# Called when the node enters the scene tree for the first time. +func _enter_tree(): + for i in range(num_balls): + var x = randf_range(-10,10) + var y = 2 + var z = randf_range(-10,10) + + var charge = randf_range(-1,1) + #if charge > -0.8 and charge < 0: + # charge = -0.8 + #if charge < 0.8 and charge > 0: + # charge = 0.8 + + var ball = preload("res://magnetic_ball.tscn").instantiate() + + ball.position = Vector3(x,y,z) + ball.charge = charge + + self.add_child(ball) + + # add force field: + var ffield = Node3D.new() + ffield.set_script(MagneticForceField) + ffield.charge = charge + ffield.affected_objects_root = self + ffield.force_strength = self.force_strength + + ball.add_child(ffield) + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + pass diff --git a/01_prototype/icon.svg b/01_prototype/icon.svg new file mode 100644 index 0000000..adc26df --- /dev/null +++ b/01_prototype/icon.svg @@ -0,0 +1 @@ + diff --git a/01_prototype/icon.svg.import b/01_prototype/icon.svg.import new file mode 100644 index 0000000..b75e6c4 --- /dev/null +++ b/01_prototype/icon.svg.import @@ -0,0 +1,37 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://b6fetoicgftd6" +path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://icon.svg" +dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/bptc_ldr=0 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 +svg/scale=1.0 +editor/scale_with_editor_scale=false +editor/convert_colors_with_editor_theme=false diff --git a/01_prototype/magnetic_ball.tscn b/01_prototype/magnetic_ball.tscn new file mode 100644 index 0000000..c2b89a2 --- /dev/null +++ b/01_prototype/magnetic_ball.tscn @@ -0,0 +1,22 @@ +[gd_scene load_steps=5 format=3 uid="uid://bs2xw1th37haf"] + +[ext_resource type="Script" path="res://scripts/physics/ForceFieldAffected.gd" id="1_gtq1a"] + +[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_7eaan"] +albedo_color = Color(0.360784, 0.568627, 0.368627, 1) + +[sub_resource type="SphereMesh" id="SphereMesh_b3k62"] +material = SubResource("StandardMaterial3D_7eaan") + +[sub_resource type="SphereShape3D" id="SphereShape3D_6pl48"] + +[node name="MagneticBall" type="RigidBody3D" node_paths=PackedStringArray("charge_color_mesh")] +mass = 3.65 +script = ExtResource("1_gtq1a") +charge_color_mesh = NodePath("MeshInstance3D") + +[node name="MeshInstance3D" type="MeshInstance3D" parent="."] +mesh = SubResource("SphereMesh_b3k62") + +[node name="CollisionShape3D" type="CollisionShape3D" parent="."] +shape = SubResource("SphereShape3D_6pl48") diff --git a/01_prototype/playground.tscn b/01_prototype/playground.tscn new file mode 100644 index 0000000..d677030 --- /dev/null +++ b/01_prototype/playground.tscn @@ -0,0 +1,73 @@ +[gd_scene load_steps=12 format=3 uid="uid://1fd7hw8r58ep"] + +[ext_resource type="Script" path="res://scripts/physics/DirectedForceField.gd" id="2_6ebjs"] +[ext_resource type="Script" path="res://MagneticBallsSpawn.gd" id="3_ix4cr"] +[ext_resource type="Script" path="res://scripts/controller/PlayerController.gd" id="3_uswcu"] + +[sub_resource type="BoxMesh" id="BoxMesh_rgta3"] +size = Vector3(100, 1, 100) + +[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_41gng"] +albedo_color = Color(0.12549, 0.141176, 1, 1) + +[sub_resource type="BoxShape3D" id="BoxShape3D_rybam"] +size = Vector3(100, 1, 100) + +[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_x5nsy"] + +[sub_resource type="Sky" id="Sky_cjapr"] +sky_material = SubResource("ProceduralSkyMaterial_x5nsy") + +[sub_resource type="Environment" id="Environment_qofx6"] +background_mode = 2 +sky = SubResource("Sky_cjapr") +ambient_light_source = 3 + +[sub_resource type="BoxMesh" id="BoxMesh_mfi73"] + +[sub_resource type="BoxShape3D" id="BoxShape3D_na5ql"] + +[node name="Node3D" type="Node3D"] + +[node name="StaticBody3D" type="StaticBody3D" parent="."] + +[node name="MeshInstance3D" type="MeshInstance3D" parent="StaticBody3D"] +mesh = SubResource("BoxMesh_rgta3") +surface_material_override/0 = SubResource("StandardMaterial3D_41gng") + +[node name="CollisionShape3D" type="CollisionShape3D" parent="StaticBody3D"] +shape = SubResource("BoxShape3D_rybam") + +[node name="Camera3D" type="Camera3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 0.825114, 0.564967, 0, -0.564967, 0.825114, 0, 7.97825, 14.5679) +environment = SubResource("Environment_qofx6") + +[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."] +transform = Transform3D(-0.561708, 0.646526, -0.516225, 0, 0.623961, 0.781455, 0.827336, 0.43895, -0.350484, -8.24679, 4.72244, -8.38021) + +[node name="MagneticBallsSpawn" type="Node3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 3.03051, 0) +script = ExtResource("3_ix4cr") +num_balls = 100 +force_strength = 200.0 + +[node name="Node3D" type="Node3D" parent="." node_paths=PackedStringArray("affected_objects_root")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.0877838, -0.356995, 0.163391) +script = ExtResource("2_6ebjs") +field_extent = Vector3(3, 5, 3) +force_strength = 100.0 +affected_objects_root = NodePath("../MagneticBallsSpawn") + +[node name="RigidBody3D" type="RigidBody3D" parent="." node_paths=PackedStringArray("camera")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.33122, 0) +axis_lock_angular_x = true +axis_lock_angular_z = true +mass = 1.24 +script = ExtResource("3_uswcu") +camera = NodePath("../Camera3D") + +[node name="MeshInstance3D" type="MeshInstance3D" parent="RigidBody3D"] +mesh = SubResource("BoxMesh_mfi73") + +[node name="CollisionShape3D" type="CollisionShape3D" parent="RigidBody3D"] +shape = SubResource("BoxShape3D_na5ql") diff --git a/01_prototype/project.godot b/01_prototype/project.godot new file mode 100644 index 0000000..36229eb --- /dev/null +++ b/01_prototype/project.godot @@ -0,0 +1,53 @@ +; Engine configuration file. +; It's best edited using the editor UI and not directly, +; since the parameters that go here are not all obvious. +; +; Format: +; [section] ; section goes between [] +; param=value ; assign values to parameters + +config_version=5 + +[application] + +config/name="01 Prototype" +run/main_scene="res://playground.tscn" +config/features=PackedStringArray("4.0", "Forward Plus") +config/icon="res://icon.svg" + +[editor] + +export/convert_text_resources_to_binary=true + +[input] + +"↑"={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"unicode":0,"echo":false,"script":null) +] +} +"↓"={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"unicode":0,"echo":false,"script":null) +] +} +"←"={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"unicode":0,"echo":false,"script":null) +] +} +"→"={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"unicode":0,"echo":false,"script":null) +] +} +jump={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"unicode":0,"echo":false,"script":null) +] +} + +[physics] + +3d/run_on_separate_thread=true +3d/physics_engine="GodotPhysics3D" diff --git a/01_prototype/scripts/controller/PlayerController.gd b/01_prototype/scripts/controller/PlayerController.gd new file mode 100644 index 0000000..148a925 --- /dev/null +++ b/01_prototype/scripts/controller/PlayerController.gd @@ -0,0 +1,44 @@ +extends RigidBody3D + +@export var camera: Camera3D +@export var speed: float = 100 +var target_y_rotation: float = 0 +var jump: bool = false + + + +func _ready(): + pass + +func _physics_process(delta): + # Get input for movement + var horizontal_input = Input.get_action_strength("→") - Input.get_action_strength("←") + var vertical_input = Input.get_action_strength("↓") - Input.get_action_strength("↑") + + # Calculate movement based on camera's rotation + var camera_relative_input = Vector3(horizontal_input, 0, vertical_input).rotated(Vector3.UP, camera.rotation.y) + # Apply movement to player + + self.apply_central_force(camera_relative_input * speed) + + if Input.get_action_strength("jump") > 0: + if not jump: + self.apply_central_impulse(Vector3.UP * 10) + jump = true + else: + jump = false + + #if camera_relative_input.length() > 0: + # var move_x = camera_relative_input.x + # var move_z = camera_relative_input.z + # + # target_y_rotation = asin(move_z / move_x) + #self.apply_torque(Vector3(0,self.rotation.y - target_y_rotation,0)) + + + + + + + + diff --git a/01_prototype/scripts/physics/DirectedForceField.gd b/01_prototype/scripts/physics/DirectedForceField.gd new file mode 100644 index 0000000..64fa5cf --- /dev/null +++ b/01_prototype/scripts/physics/DirectedForceField.gd @@ -0,0 +1,29 @@ +extends ForceField + +class_name DirectedForceField + +@export var field_extent: Vector3 = Vector3(1,5,1) +@export var force_direction: Vector3 = Vector3(0,1,0) + +# Called when the node enters the scene tree for the first time. +func _ready(): + super._ready() + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + pass + +func get_force(client): + + var t1 = self.global_position + var t2 = client.global_position + + var delta_p = t2 - t1 + + if abs(delta_p.x) < field_extent.x: + if abs(delta_p.y) < field_extent.y: + if abs(delta_p.z) < field_extent.z: + + return client.mass * self.force_strength * force_direction + + return Vector3.ZERO diff --git a/01_prototype/scripts/physics/DirectedMagneticForceField.gd b/01_prototype/scripts/physics/DirectedMagneticForceField.gd new file mode 100644 index 0000000..fb729ac --- /dev/null +++ b/01_prototype/scripts/physics/DirectedMagneticForceField.gd @@ -0,0 +1,30 @@ +extends ForceField + +class_name DirectedMagneticForceField + +@export var field_extent: Vector3 = Vector3(1,5,1) +@export var charge: float = 1.0 +@export var force_direction: Vector3 = Vector3(0,1,0) + +# Called when the node enters the scene tree for the first time. +func _ready(): + super._ready() + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + pass + +func get_force(client): + + var t1 = self.global_position + var t2 = client.global_position + + var delta_p = t2 - t1 + + if abs(delta_p.x) < field_extent.x: + if abs(delta_p.y) < field_extent.y: + if abs(delta_p.z) < field_extent.z: + var charge_factor = self.charge * client.charge * self.force_strength + return client.mass * charge_factor * force_direction + + return Vector3.ZERO diff --git a/01_prototype/scripts/physics/ForceField.gd b/01_prototype/scripts/physics/ForceField.gd new file mode 100644 index 0000000..e7680f7 --- /dev/null +++ b/01_prototype/scripts/physics/ForceField.gd @@ -0,0 +1,20 @@ +extends Node + +class_name ForceField + +@export var force_strength: float = 10 +@export var affected_objects_root: Node = null + +# Called when the node enters the scene tree for the first time. +func _ready(): + if affected_objects_root != null: + for child in affected_objects_root.get_children(): + if child is ForceFieldAffected and child != self: + child.add_force_field(self) + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + pass + +func get_force(client): + pass # overriten in clients diff --git a/01_prototype/scripts/physics/ForceFieldAffected.gd b/01_prototype/scripts/physics/ForceFieldAffected.gd new file mode 100644 index 0000000..e645e78 --- /dev/null +++ b/01_prototype/scripts/physics/ForceFieldAffected.gd @@ -0,0 +1,39 @@ +extends RigidBody3D + +class_name ForceFieldAffected + +var force_fields = [] + +@export var charge: float = -1.0 +@export var charge_color_mesh: MeshInstance3D = null + +@export var positive_charge_color: Color = Color.DARK_RED +@export var negative_charge_color: Color = Color.DARK_BLUE + + +# Called when the node enters the scene tree for the first time. +func _ready(): + var material = charge_color_mesh.get_active_material(0) + charge_color_mesh.set_surface_override_material(0,material.duplicate()) + pass # Replace with function body. + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + + var summed_force = Vector3.ZERO + + for field in force_fields: + summed_force = summed_force + field.get_force(self) + + self.apply_central_force(summed_force)# + Vector3(0,-9.81,0)) + + if charge_color_mesh != null: + var material = charge_color_mesh.get_active_material(0) + + var color = negative_charge_color.lerp(positive_charge_color, 0.5 + 0.5 * charge) + material.albedo_color = color + + +func add_force_field(force_field: ForceField): + force_fields.append(force_field) diff --git a/01_prototype/scripts/physics/MagneticForceField.gd b/01_prototype/scripts/physics/MagneticForceField.gd new file mode 100644 index 0000000..d13d176 --- /dev/null +++ b/01_prototype/scripts/physics/MagneticForceField.gd @@ -0,0 +1,27 @@ +extends ForceField + +class_name MagneticForceField + +@export var charge: float = 1.0 + +# Called when the node enters the scene tree for the first time. +func _ready(): + super._ready() + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + pass + +func get_force(client): + var t1 = self.global_position + var t2 = client.global_position + + var direction = t2 - t1 + var l = direction.length() + + var charge_factor = self.charge * client.charge * self.force_strength + + if l < 0.001: + return Vector3.ZERO + + return (1 / l**2) * client.mass * charge_factor * direction.normalized() diff --git a/01_prototype/tiles/floor_basic.glb b/01_prototype/tiles/floor_basic.glb new file mode 100644 index 0000000..bec4a12 Binary files /dev/null and b/01_prototype/tiles/floor_basic.glb differ diff --git a/01_prototype/tiles/floor_basic.glb.import b/01_prototype/tiles/floor_basic.glb.import new file mode 100644 index 0000000..06916e9 --- /dev/null +++ b/01_prototype/tiles/floor_basic.glb.import @@ -0,0 +1,30 @@ +[remap] + +importer="scene" +importer_version=1 +type="PackedScene" +uid="uid://cvactbbw6md0s" +path="res://.godot/imported/floor_basic.glb-aa59e4f92d27e9709cdae5060b3b0ed3.scn" + +[deps] + +source_file="res://tiles/floor_basic.glb" +dest_files=["res://.godot/imported/floor_basic.glb-aa59e4f92d27e9709cdae5060b3b0ed3.scn"] + +[params] + +nodes/root_type="Node3D" +nodes/root_name="Scene Root" +nodes/apply_root_scale=true +nodes/root_scale=1.0 +meshes/ensure_tangents=true +meshes/generate_lods=true +meshes/create_shadow_meshes=true +meshes/light_baking=1 +meshes/lightmap_texel_size=0.2 +skins/use_named_skins=true +animation/import=true +animation/fps=30 +animation/trimming=false +import_script/path="" +_subresources={} diff --git a/01_prototype/tiles/floor_wall1_basic.glb b/01_prototype/tiles/floor_wall1_basic.glb new file mode 100644 index 0000000..333faea Binary files /dev/null and b/01_prototype/tiles/floor_wall1_basic.glb differ diff --git a/01_prototype/tiles/floor_wall1_basic.glb.import b/01_prototype/tiles/floor_wall1_basic.glb.import new file mode 100644 index 0000000..4ff7f1a --- /dev/null +++ b/01_prototype/tiles/floor_wall1_basic.glb.import @@ -0,0 +1,30 @@ +[remap] + +importer="scene" +importer_version=1 +type="PackedScene" +uid="uid://bsaa1my5m4l01" +path="res://.godot/imported/floor_wall1_basic.glb-dc6570441337dce4af62d8a8c6d8e11b.scn" + +[deps] + +source_file="res://tiles/floor_wall1_basic.glb" +dest_files=["res://.godot/imported/floor_wall1_basic.glb-dc6570441337dce4af62d8a8c6d8e11b.scn"] + +[params] + +nodes/root_type="Node3D" +nodes/root_name="Scene Root" +nodes/apply_root_scale=true +nodes/root_scale=1.0 +meshes/ensure_tangents=true +meshes/generate_lods=true +meshes/create_shadow_meshes=true +meshes/light_baking=1 +meshes/lightmap_texel_size=0.2 +skins/use_named_skins=true +animation/import=true +animation/fps=30 +animation/trimming=false +import_script/path="" +_subresources={} diff --git a/01_prototype/tiles/floor_wall2_basic.glb b/01_prototype/tiles/floor_wall2_basic.glb new file mode 100644 index 0000000..b84c1d7 Binary files /dev/null and b/01_prototype/tiles/floor_wall2_basic.glb differ diff --git a/01_prototype/tiles/floor_wall2_basic.glb.import b/01_prototype/tiles/floor_wall2_basic.glb.import new file mode 100644 index 0000000..9a19ddb --- /dev/null +++ b/01_prototype/tiles/floor_wall2_basic.glb.import @@ -0,0 +1,30 @@ +[remap] + +importer="scene" +importer_version=1 +type="PackedScene" +uid="uid://bg03gv1vnq7ns" +path="res://.godot/imported/floor_wall2_basic.glb-dbd38f765ababc2442bb867d93cad71e.scn" + +[deps] + +source_file="res://tiles/floor_wall2_basic.glb" +dest_files=["res://.godot/imported/floor_wall2_basic.glb-dbd38f765ababc2442bb867d93cad71e.scn"] + +[params] + +nodes/root_type="Node3D" +nodes/root_name="Scene Root" +nodes/apply_root_scale=true +nodes/root_scale=1.0 +meshes/ensure_tangents=true +meshes/generate_lods=true +meshes/create_shadow_meshes=true +meshes/light_baking=1 +meshes/lightmap_texel_size=0.2 +skins/use_named_skins=true +animation/import=true +animation/fps=30 +animation/trimming=false +import_script/path="" +_subresources={}