- Edited
I'm working on a game that is mechanically 2D, but for stylistic purposes I'm putting it in a 3D space. The first real problem I've run into is getting a character's arm to point at the cursor. After searching online this is the code I tried to use:
func _physics_process(delta):
var currentFrame = $Drawing/BaseSprite.frame
#GETTING THE CURSOR POSITION
var dropPlane = Plane(Vector3(0, 0, 1), 0)
var position3D = dropPlane.intersects_ray(
$Camera.project_ray_origin(get_viewport().get_mouse_position()),
$Camera.project_ray_normal(get_viewport().get_mouse_position()))
var cursor3D = Vector3()
cursor3D.x = position3D.x
cursor3D.y = position3D.y
cursor3D.z = self.translation.z
#AIMING THE ARM
$Drawing/ShootingArm.look_at(cursor3D,Vector3(0,0,1))
It almost works.
Here's what I'm trying to do:
What I'm getting is off by about 45 degrees, and stretches the image out in a weird way:
The arm moves, but at that weird offset and with a weird stretch, so I'm thinking either the coordinates I'm getting are wrong, or I'm somehow passing a z coordinate that isn't in line with the arm, or I just fundamentally don't understand how look_at works. Any assistance would be great. Thanks.