Godot Version
v4.4.1.stable.official [49a5bc7b6]
Question
Absolute beginner here, trying to learn coding via Godot. Any help would be appreciated.
I’m having a remoteTransform3D node rotate a StaticBody3D while following a Path3D. Planet orbits star. When I run the project, my rotation comes out choppy. Am I missing a lerp, or using the function incorrectly?
extends Node3D
@export var rotation_speed_deg: float = 90.0
@export var speed: float = -0.09
@onready var the_planet: Node3D = $Node3DPlanetTemplate/StaticBody3D/CollisionShape3D
@onready var path_follow: PathFollow3D = $Node3DPlanetTemplate/Path3D/PathFollow3D
var distanceScale: float = ScaleManager.distanceScale
var timeScale: float = ScaleManager.timeScale
var bodyScale: float = ScaleManager.bodyScale
func _ready():
# Get the radius from the global singleton dictionary
var mercury_radius = 10
# Create a circular curve and assign it to the Path3D
set_path3d_circle($Node3DPlanetTemplate/Path3D, mercury_radius)
func set_path3d_circle(path: Path3D, radius: float, resolution: int = 32) -> void:
var curve := Curve3D.new()
for i in range(resolution + 1):
var angle = TAU * float(i) / float(resolution)
var x = radius * cos(angle)
var z = radius * sin(angle)
curve.add_point(Vector3(x, 0, z))
curve.closed = true
path.curve = curve
func _physics_process(delta: float) -> void:
var rotation_speed_rad = deg_to_rad(rotation_speed_deg)
the_planet.rotate_y(rotation_speed_rad * timeScale * delta)
path_follow.progress_ratio += speed * timeScale * delta
# Wrap around if progress_ratio exceeds 1.0
if path_follow.progress_ratio > 1.0:
path_follow.progress_ratio = 0.0