Should I be switching from Kinematic to Rigidbody then for this code to work?
Rotating node on specific axis in movement direction
It would need to be a KinematicBody. This will snap the rotation. Once you get the math working, you can use a linear interpolate to smooth it.
- Edited
var villagerTargetLocation : Vector3
var villagerTargetRotation : Basis
var rotationLerp = 0.0
var rotationSpeed = 1.0
func _physics_process(delta):
villagerRotationProcess(delta)
func VillagerRotation_SetTargetLocation(new_target: Vector3):
villagerTargetLocation = new_target
rotationLerp = 0
func villagerRotate(delta):
if rotationLerp < 1:
rotationLerp += delta * rotationSpeed
elif rotationLerp > 1:
norseMaleVillagerMesh_Spatial.transform.basis = transform.basis.slerp(villagerTargetRotation, rotationLerp).orthonormalized()
norseMaleVillagerStatus_Spatial.transform.basis = transform.basis.slerp(villagerTargetRotation, rotationLerp).orthonormalized()
func villagerRotationProcess(delta):
villagerTargetLocation.y = transform.origin.y
if villagerTargetLocation != transform.origin:
villagerTargetRotation = transform.looking_at(villagerTargetLocation, Vector3.UP).basis
villagerRotate(delta)
That's almost working now which is fantastic, but it's not rotating as potentially instantly as I'd like and I still need to convert the movement direction properly, I think that's why.
Ah! Full code and more up to date on their github which is useful.
https://gitlab.com/victorkarp/godot_basis_rotation/-/blob/master/Character.gd
You don't need the if statement. You can just set rotationLerp to a value like 0.3 and it will work okay.
Hmmm, need to investigate this code and poke at it some more, I think it's a bit overcomplicated for what I'm try to do and can be tidied up.
@cybereality This is all new code to me so I'm going to have to do some poking at it.
Right no problem
https://godotengine.org/qa/67967/make-3d-character-face-direction-of-movement
Holy crap think I nailed it now but kind of confused as to why, maybe I didn't implement this solution correctly before? Just a matter of smoothing everything.