Godot Version
4.4
Question
So…the fact i can’t just move the pivot point of a geo group in godot seems quite simply ridiculous. I know there’s that hack where i can attach it to another Node3D and make it the parent of it. That is, as above, a HACK…the correct way to do this would be to allow me to move the pivot point like any other object…but alas godot seems to believe this isn’t useful
Any help would be greatly appreciated as trying to “recenter” the group with a node3d and reparenting seems to simply cause somewhat random locations for my objects
So i created a Node3d called “Pivot” in the object group…which i can move around…and then added this to get around the fact it won’t let me do this natively…feels like something that should be allowed
func get_pivot() -> Vector3:
# check to see if self has a pivot as a child
for child in get_all_children(self):
if "Pivot" == child.name:
return child.global_position
return self.global_position
Sounds like you are doing it the wrong way around, your “pivot” node should be the parent of the geometry. I haven’t had this get in the way of any code so far, could you post a screenshot of your scene tree? What is problem this causes in the big picture?
The scene tree is dynamic - added to and removed from using code - this is an instanced scene that will be placed within a larger scene dynamically with mouse movement and click - the object needs to be centered around a convenient point when it is instanced to make placement simpler
The root node of the scene is an Area3D
If i am being honest the solution i have here is probably better than using a simple node3d as the root / parent node of the object group…it gives me ultimate flexibility…and i could even have multiple pivots that i could define and switch between if the object is too large and switching the pivot to a more convenient (pre-defined one) may be useful
I would add the pivot to the instanced scene, just above any imported visual elements. This has covered all of my use cases, including allowing users to place objects in the main scene.
this is what i did…however i couldn’t get the area3d to behave in the way i wanted - so i introduced the Pivot node as you have here…except not as a parent of the geometry (it is independent) which means i can move it wherever i want and have that be the point around which the geometry orbits
If “Pivot” doesn’t have any children then it isn’t influencing anythings position/rotation/transform, so it’s not really a “pivot”.
Keep in mind the root node also pivots it’s children, maybe you can make better use of the Children’s position relative to the Area3D?
1 Like
The fact it doesn’t influence the children is good…notice the code i wrote - it searches the object (and there are lots of different types of objects) for a Pivot node…if it finds it then it uses the global_position of that node as the “center”…if it doesn’t find it then it uses the object’s global_positon - in this way i can move the pivot wherever i want so i can rotate around an arbitrary point in the geometry…surely this is more flexible than simply making it be the geometric center of the node3d (or similar) that is the parent?
Suppose it depends what you are using the global_position
for; when I hear “pivot” I assume you are trying to do rotation operations around a point, which is not naturally achieved through your code, no rotation takes place in the sample. If you are only looking for distances between two points then this is as valid as any other, maybe a bit slower because of the child-iteration. What’s the big picture problem? What drove you to this initial solution in the first place?
Very large objects that i need to shift the point of rotation (of the camera) around to account for the large geometry
I changed it to be a simple get_children() call instead of the get_all_children() means the pivot needs to exist as a first generation descendant of the root but it is only iterating through 5 objects then…so pretty cheap
Ah, then you would need to parent a pivot to the camera and rotate the pivot instead, many do this for first-person or third-person cameras. You may be able to tell how large the object is by it’s collision data i.e. a raycast, or if you’ve been very careful it’s AABB.
Seems like we would really need to know more about your camera script and set up, if you aren’t happy with your solution. I’m not sure how your pivot’s position solve this issue of large objects needing an orbit, is the pivot placed far away from the center to sort of mark the orbit’s distance?
The idea i have is to have multiple pre-defined pivot points - then i can switch between them to get a different angle and camera orbit
Appreciate your help! Has been food for thought