-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
462b383
commit 33acf8a
Showing
11 changed files
with
188 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
# Godot 4+ specific ignores | ||
.godot/ | ||
recordings/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
extends VBoxContainer | ||
|
||
@export var wheel_slider: PackedScene | ||
@export var wheels: Node | ||
|
||
# Called when the node enters the scene tree for the first time. | ||
func _ready(): | ||
for wheel in wheels.get_children(): | ||
var slider = wheel_slider.instantiate() | ||
slider.init(wheel) | ||
add_child(slider) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,27 @@ | ||
extends Node3D | ||
|
||
var net_momentum = Vector3(0, 0, 0) | ||
|
||
# Called when the node enters the scene tree for the first time. | ||
func _ready(): | ||
pass # Replace with function body. | ||
|
||
var body_velocity = Vector3.ZERO | ||
const inertia: float = 6.0 | ||
|
||
|
||
func get_wheel_momentum(): | ||
var momentum: Vector3 = Vector3.ZERO | ||
for wheel in get_tree().get_nodes_in_group("wheel"): | ||
momentum += wheel.get_momentum() | ||
return momentum | ||
|
||
|
||
|
||
var count = 0 | ||
# Called every frame. 'delta' is the elapsed time since the previous frame. | ||
func _process(delta): | ||
var body_momentum = net_momentum - get_wheel_momentum() | ||
if not body_momentum.is_zero_approx(): | ||
rotate(body_momentum.normalized(), delta * body_momentum.length()) | ||
body_velocity = body_momentum / inertia | ||
if not body_velocity.is_zero_approx(): | ||
rotate(body_velocity.normalized(), delta * body_velocity.length()) | ||
|
||
DebugDraw.draw_vector(global_position, body_momentum * 0.5, Color.GREEN) | ||
count += delta | ||
if count > 0.1: | ||
DebugDraw.draw_vector(global_position, body_velocity * 0.5, Color.GREEN) | ||
count = 0 | ||
#DebugDraw.draw_vector(global_position, get_wheel_momentum() * 0.5, Color.PINK) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,27 @@ | ||
extends Node3D | ||
|
||
@export var rpm: float = 4.0 | ||
const inertia: float = 1.0 | ||
const inertia: float = 1.0 # kg * m^2 | ||
const max_velocity: float = 40.0 # rad/s | ||
|
||
# Called when the node enters the scene tree for the first time. | ||
func _ready(): | ||
pass # Replace with function body. | ||
@export var velocity: float = 0.0 # rad / s | ||
@export var acceleration: float = 0.0 # rad / s^2 | ||
|
||
|
||
# Called every frame. 'delta' is the elapsed time since the previous frame. | ||
func _process(delta): | ||
velocity += acceleration; | ||
if abs(velocity) > max_velocity: | ||
velocity = clamp(velocity, -max_velocity, max_velocity) | ||
acceleration = 0 | ||
animate(delta) | ||
|
||
|
||
func animate(delta): | ||
rotate_object_local(Vector3(0, 0, 1), rads_per_sec() * delta) | ||
rotate_object_local(Vector3(0, 0, 1), velocity * delta) | ||
|
||
func get_momentum() -> Vector3: | ||
return rads_per_sec() * inertia * get_global_transform().basis.z; | ||
return velocity * inertia * get_global_transform().basis.z; | ||
|
||
func rads_per_sec() -> float: | ||
return 0.1047198 * rpm | ||
|
||
func rpm() -> float: | ||
return 9.5492968 * velocity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
extends HBoxContainer | ||
|
||
var wheel: Node | ||
|
||
func init(_wheel: Node): | ||
wheel = _wheel | ||
$ID.text = wheel.name | ||
$Indicator.min_value = -wheel.max_velocity | ||
$Indicator.max_value = wheel.max_velocity | ||
|
||
|
||
func _process(delta): | ||
if wheel.velocity != $Indicator.value: | ||
display_velocity() | ||
|
||
func _gui_input(event): | ||
wheel.velocity = $Indicator.value | ||
|
||
func display_velocity(): | ||
$Indicator.value = wheel.velocity | ||
$RPM.text = "RPM: %.1f" % (9.5492968 * wheel.velocity) | ||
|
||
|
||
func _on_plus_button_down(): | ||
wheel.acceleration = 0.1 # Replace with function body. | ||
|
||
func _on_minus_button_down(): | ||
wheel.acceleration = -0.1 | ||
|
||
func _on_minus_button_up(): | ||
wheel.acceleration = 0 # Replace with function body. | ||
|
||
func _on_plus_button_up(): | ||
wheel.acceleration = 0 # Replace with function body. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
[gd_scene load_steps=2 format=3 uid="uid://c67ruvyiuhsk2"] | ||
|
||
[ext_resource type="Script" path="res://wheel_slider.gd" id="1_jd0x8"] | ||
|
||
[node name="WheelSlider" type="HBoxContainer"] | ||
offset_right = 40.0 | ||
offset_bottom = 40.0 | ||
script = ExtResource("1_jd0x8") | ||
|
||
[node name="ID" type="Label" parent="."] | ||
layout_mode = 2 | ||
|
||
[node name="Indicator" type="ProgressBar" parent="."] | ||
custom_minimum_size = Vector2(100, 0) | ||
layout_mode = 2 | ||
size_flags_horizontal = 3 | ||
size_flags_vertical = 1 | ||
show_percentage = false | ||
|
||
[node name="Minus" type="Button" parent="."] | ||
layout_mode = 2 | ||
text = "<-" | ||
|
||
[node name="Plus" type="Button" parent="."] | ||
layout_mode = 2 | ||
text = "->" | ||
|
||
[node name="RPM" type="Label" parent="."] | ||
layout_mode = 2 | ||
text = "RPM: " | ||
|
||
[connection signal="button_down" from="Minus" to="." method="_on_minus_button_down"] | ||
[connection signal="button_up" from="Minus" to="." method="_on_minus_button_up"] | ||
[connection signal="button_down" from="Plus" to="." method="_on_plus_button_down"] | ||
[connection signal="button_up" from="Plus" to="." method="_on_plus_button_up"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
extends WorldEnvironment | ||
|
||
|
||
func _input(event): | ||
|
||
# Camera Control | ||
if event is InputEventMouseMotion and Input.is_action_pressed("Right Click"): | ||
$CameraPivot.rotation.y -= event.relative.x*0.01 | ||
$CameraPivot.rotation.x -= event.relative.y*0.01 | ||
$CameraPivot.rotation.x = clamp($CameraPivot.rotation.x, -PI/2, PI/2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters