init
This commit is contained in:
commit
814e50a862
10 changed files with 111 additions and 0 deletions
14
entities/RoadPath.tscn
Normal file
14
entities/RoadPath.tscn
Normal file
|
@ -0,0 +1,14 @@
|
|||
[gd_scene load_steps=3 format=3 uid="uid://cjk3phtyyiyty"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bdw7xdf1lc3ud" path="res://entities/do_spline.gd" id="1_c4y0q"]
|
||||
|
||||
[sub_resource type="Curve3D" id="Curve3D_p7e7j"]
|
||||
_data = {
|
||||
"points": PackedVector3Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6.24595, 0, 10),
|
||||
"tilts": PackedFloat32Array(0, 0)
|
||||
}
|
||||
point_count = 2
|
||||
|
||||
[node name="Track" type="Path3D"]
|
||||
curve = SubResource("Curve3D_p7e7j")
|
||||
script = ExtResource("1_c4y0q")
|
26
entities/do_spline.gd
Normal file
26
entities/do_spline.gd
Normal file
|
@ -0,0 +1,26 @@
|
|||
@tool
|
||||
extends Path3D
|
||||
class_name RoadPath
|
||||
@export_tool_button("update_control_points") var action = update_control_points
|
||||
|
||||
func update_control_points():
|
||||
if curve.point_count < 2:
|
||||
return
|
||||
|
||||
|
||||
# Start point: out control based on next point
|
||||
var dir = (curve.get_point_position(1) - curve.get_point_position(0)).normalized()
|
||||
var tangent_length = dir.length() / 3
|
||||
|
||||
curve.set_point_out(0, dir * tangent_length)
|
||||
|
||||
# Intermediate points: in and out controls based on adjacent points
|
||||
for i in range(1, curve.point_count - 1):
|
||||
var prev_dir = (curve.get_point_position(i) - curve.get_point_position(i - 1)).normalized()
|
||||
var next_dir = (curve.get_point_position(i + 1) - curve.get_point_position(i)).normalized()
|
||||
tangent_length = next_dir.length() / 3
|
||||
var tangent = (prev_dir + next_dir)
|
||||
tangent.y = 0
|
||||
tangent = tangent.normalized()
|
||||
curve.set_point_in(i, -tangent * tangent_length)
|
||||
curve.set_point_out(i, tangent * tangent_length)
|
1
entities/do_spline.gd.uid
Normal file
1
entities/do_spline.gd.uid
Normal file
|
@ -0,0 +1 @@
|
|||
uid://bdw7xdf1lc3ud
|
Loading…
Add table
Add a link
Reference in a new issue