I am having a problem where I have the following objecst in a world3d:

Node3D: ( rotated in Y 90 degrees )
-> Several child nodes3D with diferent rotations and positions

I want to send the rotation and positions to another world3D ( an minimap )
Before I have rotation in the parent Node3D everything works normal, but when I add rotation to the node3D, for some reason the objects in the minimap world3d dont get its rotation and move, insted of from left to rign, to up and down.
I am sending the information to the new world as a signal, with the vectors :

signal Sig_UpdateMiniMap( objs_pos: Array[ TVector3 ] , obs_rot: Array[ TVector3 ] )

I am feeding it with this :

	for node in get_tree().root.get_child(0).get_children():
		if( utils.mySubstr(node.name,1,4)=="Obj_" ):
			var carmesh: Node3D = node.get_node("ObjMesh")
			pos:Vector3 = carmesh.transform.origin
			rot:Vector3 = carmesh.global_transform.basis.get_euler()			
			arraypos.append( pos )
			arrayrot.append( rot )

And setting in the minimap world3d with :

newobj.global_transform.basis.from_euler( obj.rot )
newobj.transform.origin = obj.pos

Nothing I tried worked... What I am doing wrong ?

  • xyz replied to this.
  • IceBergyn I cant take the parent position because its fixed, it dont move in my case, about the global space, I though I was doing that with the global_transform, there is another way to get the globals ?

    I didn't say to take parent's position, but to take position in parent's (or global) space.

    Your code takes rotation in global space, but position in local. Take both in global space.

    Instead:

    pos:Vector3 = carmesh.transform.origin

    Try:

    pos:Vector3 = carmesh.global_transform.origin

    If you need more specific answer post your exact scene structure, so we can see where in the scene hierarchy are source and target coordinate spaces located.

    xyz I cant take the parent position because its fixed, it dont move in my case, about the global space, I though I was doing that with the global_transform, there is another way to get the globals ?

    • xyz replied to this.

      Just to give a bit more context/detail, I have the following structure :
      ParentNode3D -> This have a initial y rotation for map placement
      / RigidBody3D -> this move arround
      / Mesh -> I change the position and rotation of this mesh with the rigidbody pos and rot.

      I cant also put the initial rotate in the mesh because if I do it I need to rotate also all the other meshes and rigidbodys manually.

      The ParentNode keeps in the same rest position all the time, since is the rigidbody that moves.
      The odd is that if the parentnode has no rotation the minimap shows fine, and if it has, for example 180 rotation in Y, then objs in minimap moves in the opposite direction that it should.

      It's better to work with local rotations / positions and do the transformation yourself. Then you can get whatever you want.

      For example, if you pull the Basis from the children most object (it's local rotation) you can take a blank basis and multiply it to reconstruct the original. If it is nested, and each level has a different rotation, then you need to save all those rotations (the basis) and multiply them in order to reconstruct the whole one. Translation is easier, as it is just addition of vector 3 values.

        cybereality I am not sure I understood, you said to create an blank basis, then multiply the rotation from the parentnode, then multiply it by the local rotation from the obj ?
        Another aprouch I was thinking is to use PhysicsServer3D to at the first frame, rotate the physicbody to the rotation of the parentnode, and then set the parentnode to 0,0,0 , is it a bad idea ?

        You shouldn't move / rotate physics bodies manually. It will break the physics engine.

        IceBergyn I cant take the parent position because its fixed, it dont move in my case, about the global space, I though I was doing that with the global_transform, there is another way to get the globals ?

        I didn't say to take parent's position, but to take position in parent's (or global) space.

        Your code takes rotation in global space, but position in local. Take both in global space.

        Instead:

        pos:Vector3 = carmesh.transform.origin

        Try:

        pos:Vector3 = carmesh.global_transform.origin

        If you need more specific answer post your exact scene structure, so we can see where in the scene hierarchy are source and target coordinate spaces located.

          Note, even with the global transform, that is the global transform of that scene, not the other one. So some transform may still be needed.

          • xyz replied to this.

            cybereality Note, even with the global transform, that is the global transform of that scene, not the other one. So some transform may still be needed.

            Yeah, but it really depends on the setup. If transform is taken from global space and assigned inside map's local space, it may be ok since map's local space could implicitly be doing needed transforms. Hard to tell precisely without seeing the scene.

            xyz Thanks it works now, Its kind counterintuitive, but it works, when I change the transform to also global_transform in the position as well. Thanks for also for cybereality for the documentation, I will do some reading !

            • xyz replied to this.

              IceBergyn Thanks it works now, Its kind counterintuitive

              Why do you think it's counterintuitive? Transformation is taken in the global space (so, as it appears in the world), and transferred to another space. It's quite intuitive. I'm curious why, in the first place, you took rotation and translation from different transforms, one from global and other from local?

              There's also no need to separate translation and rotation or go to/from euler for rotations. You can simply send object's whole global transform to the map, and let the map apply it to the corresponding object.

                xyz I tried diferent things, and I guess the code I copy here was the last try, I had the impression I had tried the global_transform but it seems somehow I didnt. I guess I am just spent too much hours on this at the weekend ...