Weird behavior in xform()

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

Hi all.

I’m trying to prototype a UpToDown shooter thought for dual joystick controller, like Xenowerk (mobiles), and I’m experiencing many problems in the control of the animationTree.

To simulate controls in PC I use AWSD for movement and arrows for shoot direction:

mov_joy = Input.get_vector("LEFT","RIGHT", "FORWARD", "BACK")
rot_joy = Input.get_vector("ui_left","ui_right","ui_up","ui_down")

Ok, it works fine. Problem is in animationtree when I want to strafe if shooting:
I have a BlendSpace2D node with the strafe animations asigned to vertices, so that, (0,-1) is forward, (0,1) is back, (-1,0) strafe left and (1,0) strafe right and (0,0) idle shoot.

To feed by code this node blend position, I use:

	vect_relat = player.transform.basis.xform(player.direction)
	vect_relat_2D = Vector2(vect_relat.x,vect_relat.z).normalized()
	set("parameters/disparar_tipos/blend_position",vect_relat_2D)

which supposedly gives the directions of movement related to player transform, in order to play corresponing animations.

PROBLEM:

When I test it, if I shoot up or down ( ui_up, ui_down) movements works fine and strafe correctly BUT if I try to shoot in the other axis (ui_left, ui_right), movements are the opposite, and i have no idea why.

Video:

vect_relat_2D should be (0,-1) when forward strafe, and (0,1) when back strafe.
This happens in first part, vertical movement, but not in horizontal.

xform should give the vector for direction according where player is looking at, regardless global direction.
Of course, I’ve tested global and local transform.

i’m lost, any help will be very appreciated.

:bust_in_silhouette: Reply From: heavyathan

OK, solved.

it’s not xform the proper function, as basis changes with axis.

solution is xform_inv()

vect_relat = player.global_transform.basis.xform_inv(player.direction)
vect_relat_2D = Vector2(vect_relat.x,vect_relat.z).normalized()