Neodroid  0.2.0
Machine Learning Environment Prototyping Tool
FollowTargetRotation.cs
Go to the documentation of this file.
1 using UnityEngine;
2 
3 namespace droid.Runtime.Utilities.Misc.Orientation {
4  [ExecuteInEditMode]
5  public class FollowTargetRotation : MonoBehaviour {
6  [SerializeField] Vector3 _forward;
7 
8  public Quaternion rot;
9 
12  public Transform targetPose;
13 
14  void LateUpdate() {
15  if (this.targetPose) {
16  this.rot = this.targetPose.rotation;
17 
18  var projection_on_plane = Vector3.ProjectOnPlane(this.targetPose.up, Vector3.up);
19 
20  var rot = this.transform.rotation;
21  var normalised_proj = projection_on_plane.normalized;
22  var view = Quaternion.Euler(0, -90, 0) * normalised_proj;
23  if (view != Vector3.zero) {
24  rot.SetLookRotation(view, Vector3.down);
25  }
26 
27  this.transform.rotation = rot;
28  }
29  }
30  }
31 }