Trackpad Local Coordinate System

Godot Version

4.6.2.stable.official

Question

How do I retrieve a vector from the center of my trackpad to another location on the trackpad where someone is touching the trackpad on a touch screen?

Desired behavior

When someone drags around the trackpad, I want to move the character around the playing field. To do this, I am going to determine the angle of the vector from the center of the trackpad to where the person is pressing and assign that to my ‘move_direction’. The trackpad will eventually be something that is in different positions on the screen, so I would like it to be self contained regardless of where I’ve anchored it.

The Confusion

  1. I’m assuming that it’s probably conventional to put the code in the script for the TrackPad Control node since the vectors are in relation to itself and self contained. I would then return an angle that my player character can use to move given its own behavior variables. Essentially, create “func track_pad_dir():” that returns my movement direction based on finger touch position.
  2. Even though I’ve anchored the TrackPad to the bottom center of the HUD, is the TrackPad control node origin (0, 0) still the upper left of the yellow square shown in the images below?
  3. I’m a bit lost sorting through the documentation on what to actually use to get the width and height of my trackpad control node to then create a Vector2D of the center position (or is there a built-in center position in local coordinates that I can use?
  4. In general I can do the vector math just fine and transform things around, but I’m not sure which functions in the code get me the correct vector I need for that math based on what’s local or viewport.

Setup

I have a HUD scene instanced under my primary Main node in my Main scene. In the HUD scene, the root node is a CanvasLayer ‘HUD’ under which I have a child Control node “TrackPad”. In the Trackpad scene, I have made two child Texture2D nodes to hold the artwork (‘Emitter’ and ‘Grid’).