godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.12k stars 69 forks source link

Possible Change to Syntax + Position / Rotation Copy Functions #4348

Open MossFrog opened 2 years ago

MossFrog commented 2 years ago

Describe the project you are working on

3D Web based games

Describe the problem or limitation you are having in your project

The syntax surrounding copying another node's position to another object seems arbitrarily complicated. After using tools such as THREE JS one becomes accustomed to a simple .position attribute on all 3D objects be it spatial or another form of node such as a mesh instance or a rigid body. Furthermore there exists no single built in method for copying the position of another node for quick setting up of scenes or following a moving node without causing a child parent hierarchy.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

A simple .position setter and getter attribute for all 3D objects within the engine including those that are handled by the physics engine instead of using origin.x/y/z or translation.x/y/z (Both of these can cause arbitrary confusion to the developer especially on where to use which).

Furthermore a position.copy() / rotation.copy() method for quickly snapping an object to another one's position or rotation.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

An example of this can be a spatial node (can be both nested within a parent or directly the scene root) self.position.copy(anothernode.position) self.rotation.copy(anothernode.rotation)

Or direct access self.position.x += 10.0 self.position.y = -10 etc etc...

The position should be a direct position from world space NOT LOCAL SPACE.

If this enhancement will not be used often, can it be worked around with a few lines of script?

If not used often the regular origin or translation attributes can be utilized albeit at a cost since some nodes can be shifted by moving their origin and some require translation. This can become cumbersome.

self.origin.x = anothernode.get_translation().x self.origin.y = anothernode.get_translation().y self.origin.z = anothernode.get_translation().z

Is there a reason why this should be core and not an add-on in the asset library?

It is a simple programmatic simplifcation/shorthand and would be pointless if implemented as a plugin/addon.

mrjustaguy commented 2 years ago

wouldn't something like self.position=to_local(to_global(anothernodepath.position)) work? This should get anothernode's position in global space, and set that position to self in it's local space coordinate system (so no matter where self is, if anothernode's global position is 0,0,0 that's where it'll set self in global space)

I mean, copy would not work the way you expect it, as it'd logically speaking just copy over the unmodified vector3 and result in local 0,0,0 position, which doesn't have to be global space 0,0,0 position.

Note: I'm using 4.0 terminology, where position is a thing, don't think that applies to 3.x

MossFrog commented 2 years ago

I think the absence of the position attribute in 3.x is the main issue and yes that method would work and the ambiguity of local and global space could be an issue but simply the position attribute would return local space if the node is nested and global position if not. I think my main issue is just the absence of the syntax in the current stable release.

Diddykonga commented 2 years ago

In 4.0:

Node3D: self.global_transform.origin = other.global_transform.origin (remove origin and use global_transform, if wishing to also copy scale/rotation)

Node2D: self.global_position = other.global_position (replace with global_transform, if wishing to also copy scale/rotation)

Control(2D): self.get_global_transform().origin = other.get_global_transform().origin (remove origin and use get_global_transform(), if wishing to also copy scale/rotation)

There is no need to do the to_local(to_global()) method as, setting the global will always update the local if the node is parented.