Trouble with 3d model rotation!

Godot Version

v4.4.1-stable

Question

hi there!

i’m very very new to godot and game dev in general (but having a great time!!), and as far as i can tell this is a question that gets asked a lot by beginners so i can’t apologise enough for cluttering the board! i’ve been searching and reading through a ton of different solutions but have found no luck so far, so any help would be really appreciated (and many apologies if any of my use of terminology is incorrect!)!

i’m currently trying to make my little model rotate to face the direction of movement (just the mesh, not the whole body) and have run into the same issue with all the solutions i’ve seen and tried and tinkered with- that being that the model faces the correct direction until it’s rotated with camera controls, at which point it continues to turn to face the same directions despite now moving in a different direction! sorry for the crude explanation but for lack of better language it still turns to face north when moving forwards, south when moving backwards etc despite movement no longer aligning with the x/z axes!

just as proof that i haven’t read the docs, gotten confused and decided to bother the experts (i did a bit more digging, then decided to bother them… sorry!!) here are a couple variations that i’ve either seen or tried on my own, all seemingly to the same result:

	model.look_at(global_position + input3)

	model.global_rotation.y = Vector2(input.y, input.x).angle()

    var model_rot = transform.basis.x + (100*(Vector3(input.x, 0, input.y)))
	model.look_at(model_rot)

and here’s what i’m working with so far (as far as the relevant stuff, anyway) before getting stumped!

func get_input():
	var input = Input.get_vector("left", "right", "forward", "back")
    #input3 only used for a couple things and seems more like an awkward workaround on my part than a particularly elegant solution >.>
	var input3 = Vector3(-input.x, 0, -input.y)

	var movement_dir = transform.basis * Vector3(input.x, 0, input.y)
	velocity.x = movement_dir.x * speed
	velocity.z = movement_dir.z * speed

    # where the problems start !==================
	if velocity.x or velocity.z: 
		var model_rot = transform.basis.x + (100*(Vector3(input.x, 0, input.y)))
		model.look_at(model_rot)



#initial scuffed camera setup in case it's messing with it!
func _unhandled_input(event):
	if event is InputEventMouseMotion and Input.is_action_pressed("char_turn"):
		rotate_y(-event.relative.x * mouse_sensitivity)
		springarm.rotate_x(-event.relative.y * mouse_sensitivity)

again i can’t apologise enough for bothering you nice folks with such a trivial thing (and for such a long post- conciseness is not a strength of mine) but i am really stuck and everything i try seems to lead back to the same problem- i can only assume i’m misunderstanding some of the maths behind it but i’ve tried my best to read all the relevant docs etc… any help you can offer would be really appreciated a whole bunch!

(i’m not sure how helpful a video would be but thought it was worth adding one just in case- please excuse the scuffed model and animation, godot isn’t the only thing i’m new at!)

look at the current position plus velocity direction.

2 Likes

uggh that’s so obvious thank you so much for your help!! <33

1 Like