3D Turret looking at the mouse woes.
Asked Answered
I

2

0

I've been struggling to make a turret look slerp at the mouse cursor appropriately. I've been trying to do this with Quaternions and believe I'm at the edge of understanding them, so forgive the code.

if result:
			var ray_collision_point : Vector3 = result.position
			var object_position : Vector3 = turret.position 
			var angle = Vector2(ray_collision_point.x, ray_collision_point.z).angle_to(Vector2(object_position.x, object_position.z))
			cursor.transform.origin = ray_collision_point
		
			var a = Quaternion(turret.transform.basis)
			var b = Quaternion(Vector3.UP, angle)
			var c = a.slerp(b, .5)

			turret.quaternion = c

Which results in this, the arc doesn't do what I want it to do. I think the issue is in var b, but my understanding of things is on shakey ground, so any help is appreciated.

Ihs answered 17/3 at 13:42 Comment(0)
A
0

Ihs No need to use angles when working with quaternions. Construct the wanted basis directly from 3 vectors: direction vector, up vector and their cross product.

Alkalosis answered 17/3 at 19:8 Comment(0)
I
0

That... is probably my missing piece. Outside of the pasted snippet, I've been trying to construct it with a position vector! So of course it's not going to work or make sense. Thanks. I'll see if I can't use that information to make this work properly.

Ihs answered 18/3 at 1:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.