Skip to content

Instantly share code, notes, and snippets.

@Volorf
Last active October 23, 2021 20:25
Show Gist options
  • Select an option

  • Save Volorf/2c257c879ab50918817fb48f6f81a2ca to your computer and use it in GitHub Desktop.

Select an option

Save Volorf/2c257c879ab50918817fb48f6f81a2ca to your computer and use it in GitHub Desktop.
Unity Cheap Sheet
// Vectors
Debug.Log(Vector3.forward); // (0, 0, 1.0)
Debug.Log(Vector3.right); // (1.0, 0, 0)
Debug.Log(Vector3.up); // (0, 1.0, 0)
// Rotation toward a direction
// https://answers.unity.com/questions/803365/make-the-player-face-his-movement-direction.html
float moveHorizontal = Input.GetAxisRaw ("Horizontal");
float moveVertical = Input.GetAxisRaw ("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
if(movement != Vector3.zero)
{
transform.rotation = Quaternion.Slerp(transform.rotation,
Quaternion.LookRotation(movement.normalized),
0.2f);
}
transform.Translate(movement * movementSpeed * Time.deltaTime, Space.World);
// https://www.youtube.com/watch?v=ORD7gsuLivE
Vector3 camF;
Vector3 camR;
camF = cameraGO.transform.forward;
camR = cameraGO.transform.right;
camF = camF.normalized;
camR = camR.normalized;
float xMovement = joystick.Horizontal;
float zMovement = joystick.Vertical;
Vector3 movement = camR * xMovement + camF * zMovement;
movement.y = 0f;
if(movement != Vector3.zero)
{
transform.rotation = Quaternion.Slerp(transform.rotation,
Quaternion.LookRotation(movement.normalized),
rotSmooth);
}
transform.Translate(movement * speedMove * Time.deltaTime, Space.World);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment