Skip to content

Instantly share code, notes, and snippets.

@unitycoder
Last active October 1, 2020 10:39
Show Gist options
  • Save unitycoder/63d6ed43133f9077f1533df0707777d3 to your computer and use it in GitHub Desktop.
Save unitycoder/63d6ed43133f9077f1533df0707777d3 to your computer and use it in GitHub Desktop.
rotate towards player in one axis
// lookat with fixed transform flipping in certain angles:
transform.LookAt(target, transform.up);
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