generated from krampus/template-godot4
Suddenly remembered high school physics lol
This commit is contained in:
parent
e9abc96002
commit
4e538df4b0
|
@ -28,7 +28,8 @@ const MAGNUS_EPSILON := 1e-3
|
||||||
## where `rho` is the fluid density of the medium, or 1.225 for air at sea level,
|
## where `rho` is the fluid density of the medium, or 1.225 for air at sea level,
|
||||||
## and `C_L` is the lift coefficient which for our purposes is 0.05,
|
## and `C_L` is the lift coefficient which for our purposes is 0.05,
|
||||||
## and `r` is the radius of the ball, which is 5cm.
|
## and `r` is the radius of the ball, which is 5cm.
|
||||||
@export var magnus_coefficient := 0.00024
|
#@export var magnus_coefficient := 0.00024
|
||||||
|
@export var magnus_coefficient := 0.0
|
||||||
|
|
||||||
## Causes the ball to stick to surfaces
|
## Causes the ball to stick to surfaces
|
||||||
@export var magnetic := false
|
@export var magnetic := false
|
||||||
|
|
|
@ -45,6 +45,21 @@ streams_count = 2
|
||||||
stream_0/stream = ExtResource("11_i5g55")
|
stream_0/stream = ExtResource("11_i5g55")
|
||||||
stream_1/stream = ExtResource("12_0losp")
|
stream_1/stream = ExtResource("12_0losp")
|
||||||
|
|
||||||
|
[sub_resource type="Animation" id="Animation_ll5da"]
|
||||||
|
length = 0.001
|
||||||
|
tracks/0/type = "value"
|
||||||
|
tracks/0/imported = false
|
||||||
|
tracks/0/enabled = true
|
||||||
|
tracks/0/path = NodePath("AudioStreamPlayer3D:playing")
|
||||||
|
tracks/0/interp = 1
|
||||||
|
tracks/0/loop_wrap = true
|
||||||
|
tracks/0/keys = {
|
||||||
|
"times": PackedFloat32Array(0),
|
||||||
|
"transitions": PackedFloat32Array(1),
|
||||||
|
"update": 1,
|
||||||
|
"values": [false]
|
||||||
|
}
|
||||||
|
|
||||||
[sub_resource type="Animation" id="Animation_dlkgq"]
|
[sub_resource type="Animation" id="Animation_dlkgq"]
|
||||||
resource_name = "death"
|
resource_name = "death"
|
||||||
length = 8.0
|
length = 8.0
|
||||||
|
@ -140,21 +155,6 @@ tracks/5/keys = {
|
||||||
"values": [true]
|
"values": [true]
|
||||||
}
|
}
|
||||||
|
|
||||||
[sub_resource type="Animation" id="Animation_ll5da"]
|
|
||||||
length = 0.001
|
|
||||||
tracks/0/type = "value"
|
|
||||||
tracks/0/imported = false
|
|
||||||
tracks/0/enabled = true
|
|
||||||
tracks/0/path = NodePath("AudioStreamPlayer3D:playing")
|
|
||||||
tracks/0/interp = 1
|
|
||||||
tracks/0/loop_wrap = true
|
|
||||||
tracks/0/keys = {
|
|
||||||
"times": PackedFloat32Array(0),
|
|
||||||
"transitions": PackedFloat32Array(1),
|
|
||||||
"update": 1,
|
|
||||||
"values": [false]
|
|
||||||
}
|
|
||||||
|
|
||||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_kc803"]
|
[sub_resource type="AnimationLibrary" id="AnimationLibrary_kc803"]
|
||||||
_data = {
|
_data = {
|
||||||
"RESET": SubResource("Animation_ll5da"),
|
"RESET": SubResource("Animation_ll5da"),
|
||||||
|
@ -574,8 +574,8 @@ unique_name_in_owner = true
|
||||||
transform = Transform3D(1, 0, 0, 0, 0.707107, -0.707107, 0, 0.707107, 0.707107, 0, -0.02, 0)
|
transform = Transform3D(1, 0, 0, 0, 0.707107, -0.707107, 0, 0.707107, 0.707107, 0, -0.02, 0)
|
||||||
visible = false
|
visible = false
|
||||||
initial_speed = 50.0
|
initial_speed = 50.0
|
||||||
time_step = 0.01
|
time_step = 0.1
|
||||||
max_steps = 800
|
max_steps = 100
|
||||||
|
|
||||||
[node name="ProjectedTarget" parent="ArrowPivot/ShotProjection" instance=ExtResource("6_mynqj")]
|
[node name="ProjectedTarget" parent="ArrowPivot/ShotProjection" instance=ExtResource("6_mynqj")]
|
||||||
|
|
||||||
|
|
|
@ -36,10 +36,19 @@ const PUTT_ATTRITION := 0.8325 # green?
|
||||||
## If disabled, global gravity will be used instead.
|
## If disabled, global gravity will be used instead.
|
||||||
@export var check_gravity := true
|
@export var check_gravity := true
|
||||||
|
|
||||||
|
## Improves performance by caching gravity at each point along the projection.
|
||||||
|
## This can cause problems if there is a moving gravity field.
|
||||||
|
@export var cache_gravity := true
|
||||||
|
|
||||||
var _tick_counter := 0
|
var _tick_counter := 0
|
||||||
|
|
||||||
var _debug_points: Array[Vector3] = []
|
var _debug_points: Array[Vector3] = []
|
||||||
|
|
||||||
|
var _gravity_cache: Array[Vector3] = []
|
||||||
|
|
||||||
|
var _cached_pos: Vector3
|
||||||
|
var _cached_vel: Vector3
|
||||||
|
|
||||||
@onready var polygon: CSGPolygon3D = %Polygon
|
@onready var polygon: CSGPolygon3D = %Polygon
|
||||||
@onready var path: Path3D = %Path
|
@onready var path: Path3D = %Path
|
||||||
|
|
||||||
|
@ -73,6 +82,11 @@ func _process(_delta: float) -> void:
|
||||||
var pos := global_position
|
var pos := global_position
|
||||||
var vel := -global_basis.z * initial_speed
|
var vel := -global_basis.z * initial_speed
|
||||||
|
|
||||||
|
if not cache_gravity or pos != _cached_pos or vel != _cached_vel:
|
||||||
|
_gravity_cache = []
|
||||||
|
_cached_pos = pos
|
||||||
|
_cached_vel = vel
|
||||||
|
|
||||||
var final_normal: Vector3
|
var final_normal: Vector3
|
||||||
|
|
||||||
for t in range(0, max_steps):
|
for t in range(0, max_steps):
|
||||||
|
@ -82,11 +96,13 @@ func _process(_delta: float) -> void:
|
||||||
# Get local gravity if enabled
|
# Get local gravity if enabled
|
||||||
var local_gravity := gravity * gravity_vec
|
var local_gravity := gravity * gravity_vec
|
||||||
if check_gravity and Game.settings.projection_gravity:
|
if check_gravity and Game.settings.projection_gravity:
|
||||||
local_gravity = _get_gravity(pos)
|
if t >= len(_gravity_cache):
|
||||||
|
_gravity_cache.append(_get_gravity(pos))
|
||||||
|
local_gravity = _gravity_cache[t]
|
||||||
|
|
||||||
# Integrate projectile path
|
# Integrate projectile path
|
||||||
|
var next_pos := pos + vel * time_step + 0.5 * local_gravity * time_step * time_step
|
||||||
vel += local_gravity * time_step
|
vel += local_gravity * time_step
|
||||||
var next_pos := pos + vel * time_step
|
|
||||||
|
|
||||||
# Collision
|
# Collision
|
||||||
if check_collision and Game.settings.projection_collisions:
|
if check_collision and Game.settings.projection_collisions:
|
||||||
|
|
|
@ -35,6 +35,57 @@ point_count = 2
|
||||||
curve_x = SubResource("Curve_ndj60")
|
curve_x = SubResource("Curve_ndj60")
|
||||||
curve_y = SubResource("Curve_nld14")
|
curve_y = SubResource("Curve_nld14")
|
||||||
|
|
||||||
|
[sub_resource type="Animation" id="Animation_4aged"]
|
||||||
|
length = 0.001
|
||||||
|
tracks/0/type = "value"
|
||||||
|
tracks/0/imported = false
|
||||||
|
tracks/0/enabled = true
|
||||||
|
tracks/0/path = NodePath("AlertContainer/GradientBG:modulate")
|
||||||
|
tracks/0/interp = 1
|
||||||
|
tracks/0/loop_wrap = true
|
||||||
|
tracks/0/keys = {
|
||||||
|
"times": PackedFloat32Array(0),
|
||||||
|
"transitions": PackedFloat32Array(1),
|
||||||
|
"update": 0,
|
||||||
|
"values": [Color(1, 1, 1, 1)]
|
||||||
|
}
|
||||||
|
tracks/1/type = "value"
|
||||||
|
tracks/1/imported = false
|
||||||
|
tracks/1/enabled = true
|
||||||
|
tracks/1/path = NodePath("AlertContainer/Text/Subheading:modulate")
|
||||||
|
tracks/1/interp = 1
|
||||||
|
tracks/1/loop_wrap = true
|
||||||
|
tracks/1/keys = {
|
||||||
|
"times": PackedFloat32Array(0),
|
||||||
|
"transitions": PackedFloat32Array(1),
|
||||||
|
"update": 0,
|
||||||
|
"values": [Color(1, 1, 1, 1)]
|
||||||
|
}
|
||||||
|
tracks/2/type = "value"
|
||||||
|
tracks/2/imported = false
|
||||||
|
tracks/2/enabled = true
|
||||||
|
tracks/2/path = NodePath(".:modulate")
|
||||||
|
tracks/2/interp = 1
|
||||||
|
tracks/2/loop_wrap = true
|
||||||
|
tracks/2/keys = {
|
||||||
|
"times": PackedFloat32Array(0),
|
||||||
|
"transitions": PackedFloat32Array(1),
|
||||||
|
"update": 0,
|
||||||
|
"values": [Color(1, 1, 1, 1)]
|
||||||
|
}
|
||||||
|
tracks/3/type = "value"
|
||||||
|
tracks/3/imported = false
|
||||||
|
tracks/3/enabled = true
|
||||||
|
tracks/3/path = NodePath("Desaturator:material:shader_parameter/saturation")
|
||||||
|
tracks/3/interp = 1
|
||||||
|
tracks/3/loop_wrap = true
|
||||||
|
tracks/3/keys = {
|
||||||
|
"times": PackedFloat32Array(0),
|
||||||
|
"transitions": PackedFloat32Array(1),
|
||||||
|
"update": 0,
|
||||||
|
"values": [1.0]
|
||||||
|
}
|
||||||
|
|
||||||
[sub_resource type="Animation" id="Animation_l6yhv"]
|
[sub_resource type="Animation" id="Animation_l6yhv"]
|
||||||
resource_name = "display"
|
resource_name = "display"
|
||||||
length = 8.0
|
length = 8.0
|
||||||
|
@ -116,57 +167,6 @@ tracks/5/keys = {
|
||||||
"values": [1.0, 0.0, 0.0, 1.0]
|
"values": [1.0, 0.0, 0.0, 1.0]
|
||||||
}
|
}
|
||||||
|
|
||||||
[sub_resource type="Animation" id="Animation_4aged"]
|
|
||||||
length = 0.001
|
|
||||||
tracks/0/type = "value"
|
|
||||||
tracks/0/imported = false
|
|
||||||
tracks/0/enabled = true
|
|
||||||
tracks/0/path = NodePath("AlertContainer/GradientBG:modulate")
|
|
||||||
tracks/0/interp = 1
|
|
||||||
tracks/0/loop_wrap = true
|
|
||||||
tracks/0/keys = {
|
|
||||||
"times": PackedFloat32Array(0),
|
|
||||||
"transitions": PackedFloat32Array(1),
|
|
||||||
"update": 0,
|
|
||||||
"values": [Color(1, 1, 1, 1)]
|
|
||||||
}
|
|
||||||
tracks/1/type = "value"
|
|
||||||
tracks/1/imported = false
|
|
||||||
tracks/1/enabled = true
|
|
||||||
tracks/1/path = NodePath("AlertContainer/Text/Subheading:modulate")
|
|
||||||
tracks/1/interp = 1
|
|
||||||
tracks/1/loop_wrap = true
|
|
||||||
tracks/1/keys = {
|
|
||||||
"times": PackedFloat32Array(0),
|
|
||||||
"transitions": PackedFloat32Array(1),
|
|
||||||
"update": 0,
|
|
||||||
"values": [Color(1, 1, 1, 1)]
|
|
||||||
}
|
|
||||||
tracks/2/type = "value"
|
|
||||||
tracks/2/imported = false
|
|
||||||
tracks/2/enabled = true
|
|
||||||
tracks/2/path = NodePath(".:modulate")
|
|
||||||
tracks/2/interp = 1
|
|
||||||
tracks/2/loop_wrap = true
|
|
||||||
tracks/2/keys = {
|
|
||||||
"times": PackedFloat32Array(0),
|
|
||||||
"transitions": PackedFloat32Array(1),
|
|
||||||
"update": 0,
|
|
||||||
"values": [Color(1, 1, 1, 1)]
|
|
||||||
}
|
|
||||||
tracks/3/type = "value"
|
|
||||||
tracks/3/imported = false
|
|
||||||
tracks/3/enabled = true
|
|
||||||
tracks/3/path = NodePath("Desaturator:material:shader_parameter/saturation")
|
|
||||||
tracks/3/interp = 1
|
|
||||||
tracks/3/loop_wrap = true
|
|
||||||
tracks/3/keys = {
|
|
||||||
"times": PackedFloat32Array(0),
|
|
||||||
"transitions": PackedFloat32Array(1),
|
|
||||||
"update": 0,
|
|
||||||
"values": [1.0]
|
|
||||||
}
|
|
||||||
|
|
||||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_em7mg"]
|
[sub_resource type="AnimationLibrary" id="AnimationLibrary_em7mg"]
|
||||||
_data = {
|
_data = {
|
||||||
"RESET": SubResource("Animation_4aged"),
|
"RESET": SubResource("Animation_4aged"),
|
||||||
|
|
Loading…
Reference in New Issue