I am trying rotate object so his Y-axis always points in direction of another object, and continue moving forward at the same time. However, if I use following code, object always rotates and moving toward world forward axis, not local, even if on start, he was facing in another direction.
swingDirection = transform.forward*acceleration;
Vector3 testPos = transform.position + swingDirection*Time.deltaTime;
float newLenghtSq = (testPos - linePoint).sqrMagnitude;
if (newLenghtSq > lineLenghtSq)
{
testPos = linePoint + (testPos - linePoint).normalized * lineLenght;
}
Vector3 myUp = (transform.position - linePoint);
transform.rotation = Quaternion.FromToRotation(Vector3.up, -myUp);
//transform.position = testPos+transform.forward*acceleration;
Vector3 moveDir = (testPos-transform.position) + transform.forward * acceleration;
controller.Move(moveDir);