Getting a new Vector3 based on a object's rotation

Godot Version : 4.4

Hello!

I am attempting to get a Vector3 (Position) for the middle of each end of the cylindrical part of a CapsuleShape3D consistently, regardless if its rotated, moved (or scaled in the CapsuleShape3D settings)

I believe I’ve gotten the distance the points need to be offset by, with (height - (radius * 2)) / 2. I’ve just been having a hard time trying to figure out how to apply it based on the rotation and global position of the capsule to get the Vector3s I’m looking for (Points A and B in the image I made above)

Must this Vector3 be calculated at run-time through script? If not, they simplest solution could be of adding a simple Node3D as child of your CapsuleShape3D. Position it right at the center between point A and B and then simply refer to that new node whenever you need the center of the object.

If it must be obtained through code, then I would suggest looking at a solution similar to how third-person cameras are handled. If you think about it the problem is not much different than having a camera at a certain offset from the player’s head (i.e. point A)

1 Like

Do you not get the correct result if you:

    var dst_endpos: Vector3 = src_endpos * object.transform
1 Like