Odd behavior when rotating a node that has offset child nodes via script

Godot Version

4.2.2.Stable.Official

Question

I currently have an AnimatableBody3D node with a CSGBox3D and CollisionShape3D attached to it, the main goal is to rotate the AnimatableBody3D node so the shapes below work as pendulums for the player to jump across. The rotation logic works, however, it is modifying the position of the entire thing over time, slowly raising it into the air. I have no idea why as there is no position values being modified and when I use Axis Lock they no longer swing, only rotate in place. I have tested with objects that are not offset from the root node and no position issues occur, so it has something to do with offsetting them in this way. Any help is appreciated, and code snips are attached below!

Variables Used

@export var rotation_direction: Vector3 # 0 or 1 values only

@export var loopRotAmplitude: float = 0.1
@export var loopRotSpeed: float = 1

@onready var pivot: AnimatableBody3D = self

Main Logic

func _physics_process(delta: float) -> void:
		var rot: float = get_sine()
		var rawRot = rotation_direction * rot
		pivot.rotation = pivot.rotation.lerp(rawRot, 1 * delta)

Sine calculation for swing motion

func get_sine():
	return (sin(time * loopRotSpeed) * loopRotAmplitude)

Images

firefox_yimqVqHfwt

There could be errors accumulated as something is rotated. You can try and orthonormalize the transform of the rotated node to see if that solves the the creeping issue.

Tried to orthonormalize the transforms, and unfortunately that causes rotation to not work at all anymore. Modified script below:

		var rot: float = get_sine()
		var rawRot = rotation_direction * rot
		pivot.rotation = pivot.rotation.lerp(rawRot, 1 * delta)
		pivot.transform = pivot.transform.orthonormalized()

Perhaps I have this calculating in the wrong point in the chain, still fairly new to GDScript so forgive me if this is a easy fix and im just missing it. :woozy_face:

1 Like

That looks good to me, that is very strange though.
It shouldn’t matter when you do it.

Unless the rotation method is really messing with the basis… one sec

…Yeah not sure. I don’t see anything logically wrong

1 Like

That’s what I thought as well, glad It’s not just me.