Last active
October 1, 2020 10:39
-
-
Save unitycoder/63d6ed43133f9077f1533df0707777d3 to your computer and use it in GitHub Desktop.
rotate towards player in one axis
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
// lookat with fixed transform flipping in certain angles: | |
transform.LookAt(target, transform.up); |
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
using UnityEngine; | |
public class LookTowardsPlayerOneAxis : MonoBehaviour | |
{ | |
public Transform target; | |
void LateUpdate() | |
{ | |
// note Y position is set to current | |
Vector3 targetPos = new Vector3(target.position.x, transform.position.y, target.position.z); | |
transform.LookAt(2 * transform.position - targetPos); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment