Skip to content

Instantly share code, notes, and snippets.

@bartwttewaall
Created July 22, 2019 07:30
Show Gist options
  • Save bartwttewaall/764eff36566953845d09d62b20c47c00 to your computer and use it in GitHub Desktop.
Save bartwttewaall/764eff36566953845d09d62b20c47c00 to your computer and use it in GitHub Desktop.
Position and rotate a reticle on the floor, at the feet of a player in the 3D direction we're aiming at a range from the center
Transform aimTransform;
float spriteOffsetY = 0.01f;
float aimRange = 1.5f;
// use incoming player.state.aimDirection to calculate the rotation and position of the reticle's aimTransform
Vector3 aim = player.state.aimDirection.normalized;
aimTransform.localPosition = new Vector3 (aim.x * aimRange, spriteOffsetY, aim.z * aimRange);
float angle = Mathf.Atan2 (aim.x, aim.z) * (180 / Mathf.PI);
aimTransform.rotation = Quaternion.Euler (90, angle, 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment