0 votes

I'm new to the engine and I'm getting desperate. Even the most basic operation takes hours to be set straight. I just don't understand this stuff or why, when I finally find the function I'm looking for, looks like it doesn't work for X reason.

What I'm trying to do:

when I click a specific button, an MeshInstance node is set to a specific mesh and its position should be set relative to the origin.

My code:

func toSphere():
print (a)
self.mesh = SphereMesh.new()
global_translate(Vector3(0, 0, 0))

func toCube():
print (a)
self.mesh = CubeMesh.new()
global_translate(Vector3(0, 0, 0))

func toHead():
print (a)
self.mesh = getnode("MeshHead").mesh
global_translate(Vector3(-0.574,0.91,0.684))

What happens:

Function "toHead" moves the mesh how it's supposed to be moved, but when I click the others (that are supposed to move the MeshInstance back to world origin) the MeshInstance just stays there. That also means each time I activate the "toHead" function the MeshInstance adds another offset.
Halp pls.

in Engine by (17 points)

1 Answer

+1 vote
Best answer

First not sure why your are using globaltranslate, but whatever your are using, globaltranslate or translate, you have to realize the vector in parameter is a delta, not an absolute position. In other words when your translate with a zero vector this is normal it is not moving because this is what you tell your node to do.

by (1,049 points)
selected by

I used globaltranslate because I thought that would give me an absolute position! How can I get an absolute position? Should I use the root or something?
I understand it's all very noobie but I'm really at text scripting and I'm having kind of a hard time.

If you want to position your node at a specific position instead of translating it, just set the transform.origin vector.

All nodes position are relative to the parent coordinates, the absolute allows to change the position in world coordinates instead but does not change the way a translate is working.

Hey man!
Thanks. I couldn't find the right function to do that. Coming from Blueprints visual scripting, there are lots of differences I have to understand before becoming truly productive. Tried what you suggested and worked perfectly. Thanks again!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.