I'm having a very hard time with rotation and would apprecate some help. I thought this would be a simple problem but it's been a feel days and I still can't get the behavior I'd like and I feel like I have to be missing something.
I have a 3D 3rd person character game and I simple want my character to rotate along the y axis and walk that direction. So with WASD input on a press of W they'd rotate forward and move forward, etc. Movement was easy, I've still not gotten rotation to behave as I'd like.
I can't even recall everything I've tried as it's been spread out over a couple days now. The main problem is that all the built in rotation methods want you to "turn by x degrees" and not "turn to x angle" and how many degrees the player has to turn in order to face a given direction will vary depending upon their starting rotation.
I'm just not sure what to do. Can someone please offer some suggestions? Here's my movement code, not much to it, along with a bunch of stuff I have commented out that I was messing with to try and get working.
var input_dir := Input.get_vector("turn_left", "turn_right", "move_fwd", "move_bck")
var direction: Vector3 = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
if direction:
#look_at(position + direction)
#velocity = Vector3.FORWARD * SPEED
velocity.x = direction.x * SPEED
velocity.z = direction.z * SPEED
var rotation_template: String = "%s, %s"
var rotation_lookup: String = rotation_template % [str(direction.x), str(direction.y)]
transform.basis.y.y = ROTATION_TABLE[rotation_lookup]
#transform.basis = Basis(Vector3.UP, 0.1) * transform.basis
#basis = Basis.looking_at(direction)
#rotation.angle_to()
#rotate_y(0.1)
#rotate_toward()
#look_at(position + direction)