3 body problem with dot trail

This commit is contained in:
2025-12-22 23:40:35 -08:00
commit 4f1ea4e8b9
18 changed files with 228 additions and 0 deletions

4
.editorconfig Normal file
View File

@@ -0,0 +1,4 @@
root = true
[*]
charset = utf-8

2
.gitattributes vendored Normal file
View File

@@ -0,0 +1,2 @@
# Normalize EOL for all files that Git considers text files.
* text=auto eol=lf

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
# Godot 4+ specific ignores
.godot/
/android/

44
Blob.gd Normal file
View File

@@ -0,0 +1,44 @@
extends RigidBody3D
class_name Blob3D
const DOT_SPACING: float = 1.0
var cumulative_delay: float
var dot_color: Color
func _init(
material: StandardMaterial3D,
initial_position: Vector3,
initial_velocity: Vector3,
radius: float = 0.5,
mass: float = 1,
) -> void:
self.position = initial_position
self.linear_velocity = initial_velocity
self.mass = mass
var mesh = MeshInstance3D.new()
mesh.mesh = SphereMesh.new()
mesh.mesh.radius = radius
mesh.mesh.height = 2*radius
mesh.material_override = material
var collision = CollisionShape3D.new()
collision.shape = SphereShape3D.new()
collision.shape.radius = radius
self.add_child(mesh)
self.add_child(collision)
self.dot_color = random_color()
func _process(delta: float) -> void:
self.cumulative_delay += delta
if self.cumulative_delay >= DOT_SPACING:
self.add_sibling(OrbitDot3D.new(self.position, self.dot_color))
self.cumulative_delay = 0
func random_color() -> Color:
return Color.from_hsv(randf(), 0.8, 0.8)

1
Blob.gd.uid Normal file
View File

@@ -0,0 +1 @@
uid://sbifwu5mnc67

10
camera_3d.gd Normal file
View File

@@ -0,0 +1,10 @@
extends Camera3D
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
print("Created camera.")
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass

1
camera_3d.gd.uid Normal file
View File

@@ -0,0 +1 @@
uid://4wscni70so3k

23
dot.gd Normal file
View File

@@ -0,0 +1,23 @@
extends MeshInstance3D
class_name OrbitDot3D
var expiration: float = 120.0
var delay: float
func _init(position: Vector3, color: Color) -> void:
self.position = position
self.mesh = SphereMesh.new()
self.mesh.radius = 0.1
self.mesh.height = 2*self.mesh.radius
self.material_override = StandardMaterial3D.new()
self.material_override.albedo_color = color
self.delay = 0
func _process(delta: float) -> void:
self.delay += delta
if delay >= self.expiration:
self.queue_free()

1
dot.gd.uid Normal file
View File

@@ -0,0 +1 @@
uid://bolr2a1petpon

1
icon.svg Normal file
View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="128" height="128"><rect width="124" height="124" x="2" y="2" fill="#363d52" stroke="#212532" stroke-width="4" rx="14"/><g fill="#fff" transform="translate(12.322 12.322)scale(.101)"><path d="M105 673v33q407 354 814 0v-33z"/><path fill="#478cbf" d="m105 673 152 14q12 1 15 14l4 67 132 10 8-61q2-11 15-15h162q13 4 15 15l8 61 132-10 4-67q3-13 15-14l152-14V427q30-39 56-81-35-59-83-108-43 20-82 47-40-37-88-64 7-51 8-102-59-28-123-42-26 43-46 89-49-7-98 0-20-46-46-89-64 14-123 42 1 51 8 102-48 27-88 64-39-27-82-47-48 49-83 108 26 42 56 81zm0 33v39c0 276 813 276 814 0v-39l-134 12-5 69q-2 10-14 13l-162 11q-12 0-16-11l-10-65H446l-10 65q-4 11-16 11l-162-11q-12-3-14-13l-5-69z"/><path d="M483 600c0 34 58 34 58 0v-86c0-34-58-34-58 0z"/><circle cx="725" cy="526" r="90"/><circle cx="299" cy="526" r="90"/></g><g fill="#414042" transform="translate(12.322 12.322)scale(.101)"><circle cx="307" cy="532" r="60"/><circle cx="717" cy="532" r="60"/></g></svg>

After

Width:  |  Height:  |  Size: 995 B

43
icon.svg.import Normal file
View File

@@ -0,0 +1,43 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://b25a736wmlgp1"
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/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
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

47
main.gd Normal file
View File

@@ -0,0 +1,47 @@
extends Node3D
var blobs = []
var G = 0.1
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
create_blobs()
for blob in self.blobs:
self.add_child(blob)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
calculate_gravity(delta)
func calculate_gravity(delta: float) -> void:
for blob in self.blobs:
var accel: Vector3 = Vector3(0,0,0)
for other_blob in self.blobs:
if other_blob != blob:
var dist: Vector3 = other_blob.global_position - blob.global_position
accel += other_blob.mass * dist.normalized() / dist.length_squared()
blob.apply_central_impulse(G * blob.mass * accel * delta)
func create_blobs() -> void:
var planetite: StandardMaterial3D = load("res://materials/planetite.tres")
var spacing = 2
var width = 5
var height = 3
self.blobs.append(Blob3D.new(planetite, Vector3(0,0,0), Vector3(0,0,0), 0.5, 50))
self.blobs.append(Blob3D.new(planetite, Vector3(0,0,4), Vector3(0,1,0), 0.2))
self.blobs.append(Blob3D.new(planetite, Vector3(0,0,-6), Vector3(0,-1.2,0), 0.3, 2))
#for z in range(width):
# for y in range(height):
# self.blobs.append(Blob3D.new(
# planetite,
# Vector3(
# 0,
# spacing * (z - width/2),
# spacing * (y - height/2),
# )
# ))

1
main.gd.uid Normal file
View File

@@ -0,0 +1 @@
uid://bvercqvetau4

14
main.tscn Normal file
View File

@@ -0,0 +1,14 @@
[gd_scene load_steps=3 format=3 uid="uid://cgbep21nbp5lo"]
[ext_resource type="Script" uid="uid://bvercqvetau4" path="res://main.gd" id="1_ig7tw"]
[ext_resource type="Script" uid="uid://4wscni70so3k" path="res://camera_3d.gd" id="2_0xm2m"]
[node name="Main" type="Node3D"]
script = ExtResource("1_ig7tw")
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
transform = Transform3D(0.6706596, -0.47097108, 0.5730637, 1.870666e-08, 0.77256745, 0.63493276, -0.74176526, -0.42582372, 0.51812977, 3.5419807, 5.591663, 6.795337)
[node name="Camera3D" type="Camera3D" parent="."]
transform = Transform3D(-4.371139e-08, 0, 1, -0.0037873555, 0.99999285, -1.6555056e-10, -0.99999285, -0.0037873555, -4.3711076e-08, 65.657364, 0, 24.970047)
script = ExtResource("2_0xm2m")

3
materials/orbit_dot.tres Normal file
View File

@@ -0,0 +1,3 @@
[gd_resource type="StandardMaterial3D" format=3 uid="uid://dnxdmrh6a3kbi"]
[resource]

4
materials/planetite.tres Normal file
View File

@@ -0,0 +1,4 @@
[gd_resource type="StandardMaterial3D" format=3 uid="uid://b2picrcnsm0sm"]
[resource]
albedo_color = Color(0, 0, 1, 1)

3
node_3d.tscn Normal file
View File

@@ -0,0 +1,3 @@
[gd_scene format=3 uid="uid://ba53hmyqs4tl2"]
[node name="Node3D" type="Node3D"]

23
project.godot Normal file
View File

@@ -0,0 +1,23 @@
; 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="PlanetSim"
run/main_scene="uid://cgbep21nbp5lo"
config/features=PackedStringArray("4.5", "Forward Plus")
config/icon="res://icon.svg"
[physics]
3d/physics_engine="Jolt Physics"
3d/default_gravity=0.0
3d/default_linear_damp=0.0
3d/default_angular_damp=0.0