Created
July 22, 2019 07:30
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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