Updating 3D Curve in path while parent not at pos 0,0,0 causing path to offset unnaturally

Godot Version

v4.2.1.stable.official [b09f793f5]

Question

I am trying to make a graph appear by using a Path3D that I am adding points to using gdscript, and then using a CSGPolygon3D in path mode to display said curve, which is working fine if the parent of the path is in position 0,0,0.

As soon as I move the parent of the path (or its parents) off the center position of 0,0,0, the polygon /path starts displaying pretty much double what the original movement was, while any other children of the moved parent stay in the correct relative position.

I’ve checked the points being added are correct (between the correct ranges), and as you may see from the gif, the issue only happens when the a point is updated on the curve, not when the parent is moved.

Am I doing something silly, or is there a way to get around this so I can update my path when its parent is not in the 0,0,0 pos (as I want to the graph around in 3d space while paths get updated)

Any help or ideas on how to get this working would be very much appreciated.

Thanks
Graph_doing_wierd_things

The code is pretty simple

extends Node3D

var _graph_range = 5.0
var _curve:Curve3D
var _rng
var _backing:CSGPolygon3D
var _move_speed = 1.0

func _ready():
	#Setup some of the variables for easy access
	_curve = $Chart_backing/Path3D.curve
	_backing = $Chart_backing
	_rng = RandomNumberGenerator.new()
	
	#Set the backing polygon to our range
	_backing.polygon[0].y = -_graph_range
	_backing.polygon[1].y = _graph_range
	_backing.polygon[2].y = _graph_range
	_backing.polygon[3].y = -_graph_range
	
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
	#if we have added a point for this second, return
	var x_pos = ceil(Time.get_ticks_msec() / 1000.0) 
	
	#After 5 seconds, starting moving the backing up and down to see the issue
	if(x_pos > 5.0):
		if _move_speed > 0 and _backing.position.y > _graph_range :
			_move_speed = -_move_speed
		elif _move_speed < 0 and _backing.position.y < -_graph_range :
			_move_speed = -_move_speed
			
		_backing.position.y +=_move_speed * delta
		
	#If the calced x position is teh same as or less than the current number of points, skip
	if(x_pos <= _curve.point_count):
		return
		
	#Add a new point with the xpos
	_add_new_point(x_pos)
	

	
#Adds a new point to the curve on the XPos
#Point uses the _graph_range to pick a random point in between it
func _add_new_point(x_pos):
	var new_y_val = _rng.randf_range(-_graph_range, _graph_range)
	_curve.add_point(Vector3(x_pos,new_y_val,0))
	print("adding y Path : ", new_y_val)
	
	
	#And just to keep things looking okay,  update the backing size	
	_backing.polygon[2].x = x_pos
	_backing.polygon[3].x = x_pos

The TSCN file for reference that I am using for testing is as follows :

[gd_scene load_steps=4 format=3 uid="uid://bak2567nq6y8m"]

[ext_resource type="Script" path="res://Testing.gd" id="1_gqwhc"]

[sub_resource type="Curve3D" id="Curve3D_bmnv2"]

[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_1m782"]
albedo_color = Color(0.772549, 0.823529, 1, 1)
emission_enabled = true
emission = Color(0, 0.686275, 0.937255, 1)

[node name="Testing" type="Node3D"]
script = ExtResource("1_gqwhc")

[node name="Chart_backing" type="CSGPolygon3D" parent="."]

[node name="Path3D" type="Path3D" parent="Chart_backing"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.1)
curve = SubResource("Curve3D_bmnv2")

[node name="Chart_Poly" type="CSGPolygon3D" parent="Chart_backing"]
polygon = PackedVector2Array(0, 0, 0.00362897, 0.215703, 0.225661, 0.212485, 0.244968, 0.0129781)
mode = 2
path_node = NodePath("../Path3D")
path_interval_type = 0
path_interval = 1.0
path_simplify_angle = 0.0
path_rotation = 2
path_local = false
path_continuous_u = true
path_u_distance = 1.0
path_joined = false
material = SubResource("StandardMaterial3D_1m782")

[node name="Camera3D" type="Camera3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 42.913, 0, 32.335)

I think I figured this out for anyone who comes across this, though it feels a little clunky.

I set the path transform “Top Level” as true, and then if creating the line using GDScript, resetting the Path3D position to Vector3(0,0,0)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.