Why can't I use Transform2D's methods?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By fatcat__25

I am attempting to make a control inheriting node move with the mouse when clicked and dragged. For this, I need to transform global coordinates into local coordinates in the node’s code. This is the code I’m attempting to use:

func _process(delta):
    if Input.is_action_pressed("lclick"):
	    if moving == true:
		    var global_position = get_viewport().get_mouse_position()
		    rect_position = Transform2D.xform_inv(global_position)

It gives me the error Static Constant 'xform_inv' not present in built-in type Transfrom2D. Additionally, when typing a “.” after Transform2D, autocomplete only offers its constants, not its properties or methods. Why does Godot not allow me to use Transform2D’s methods or properties? Is this a result of my use case? An engine bug? Any help would be appreciated!

:bust_in_silhouette: Reply From: jgodfrey

xform_inv() is not a static function, so you need an object instance to use it. Anything that inherits from Node2D has a transform property. Using that, you can call xform_inv() on that object.

So, for example, if you have a script associated with a Node2D (or anything that inherits from it), you can do this:

transform.xform_inv(some_vector2_var)

I created a reference to a Node2D to test with. The resulting code is:

rect_position = node2d.transfrom.xform_inv(global_position)

Now upon running the code I get the error Invalid get index 'transform' (on base 'Node2D'). I clearly am completely not understanding something.

fatcat__25 | 2022-04-20 21:25

Your code is written as transfrom, not transform (notice the transposed ro). Is that the problem?

jgodfrey | 2022-04-20 21:55

It appears so. * facepalm *

fatcat__25 | 2022-04-20 22:31