0 votes

Last day I was making a joystick handle that would follow the mouse when clicked. To get the local position of the mouse position relative to the joystick background node(which I had to for my algorithm to clamp the max distance the handle could go) I used background.transform.xforminv, but, unfortunately, it didn't work. So i tried using background.tolocal which,surprisingly, worked. Now my question is: Isn't node.transform.xforminv supposed to do the same as Node.tolocal? Or am I missing something?
Btw the Node architecture i was using was the following: Player(Node2D) ->TouchControls(Canvas Layer) -> Joystick(Area2D) -> Background(TouchScreenButton) -> Handle(Sprite)
Thanks in advance for any help in clarifying this question,

Godot version 3.2
in Engine by (101 points)

1 Answer

+1 vote
Best answer

When you use a self.transform.xform, you go from a Vector local to get_parent() into a Vector local to self. When you request the cursor position however, you get a global position, so you use to_local() instead. It will do xforms starting from the first Node2D grandparent down to you node.

by (2,720 points)
selected by

But even if I use the global transform it doesnt work with xform..

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.