I’m trying to translate an object in the specific direction of a vector, however using transform.Translate seems to move it in another direction. I’m fairly certain this script works, because when I use a similar method on objects whose motion is controlled by animations it works perfectly. Printing the vector in the debugger also shows it pointing in the right direction, so I am confused as to why it isn’t working here.
In this instance, however, what usually happens is the object will move in one direction horizontally when pressing W or S, and the other when pressing A and D. Pressing a combination of W or S and A or D will result in forward and backwards motion. I’ve drawn up an example in case the explanation was hard to understand.
Any help fixing the issue would be appreciated. Here is the code in question:
float horizontal = Input.GetAxis ("Horizontal");
float vertical = Input.GetAxis ("Vertical");
Vector3 stickDirection = new Vector3 (horizontal, 0, vertical);
Vector3 nothing = new Vector3 (0,0,0);
Vector3 cameraDirection = camera.transform.forward;
cameraDirection.y = 0.0f;
Quaternion referentialShift = Quaternion.FromToRotation (Vector3.forward, cameraDirection);
Vector3 moveDirection = referentialShift * stickDirection;
if (moveDirection == nothing) return;
cube.transform.rotation = Quaternion.Lerp (cube.transform.rotation, Quaternion.LookRotation (moveDirection.normalized), Time.deltaTime * 12f);
Vector3 move = transform.forward * stickDirection.sqrMagnitude * moveSpeed;
cube.transform.Translate(move * Time.deltaTime);