You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
847 B
25 lines
847 B
10 months ago
|
using UnityEngine;
|
||
|
|
||
|
namespace Unity.MLAgentsExamples
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// Utility class to allow a stable observation platform.
|
||
|
/// </summary>
|
||
|
public class OrientationCubeController : MonoBehaviour
|
||
|
{
|
||
|
//Update position and Rotation
|
||
|
public void UpdateOrientation(Transform rootBP, Transform target)
|
||
|
{
|
||
|
var dirVector = target.position - transform.position;
|
||
|
dirVector.y = 0; //flatten dir on the y. this will only work on level, uneven surfaces
|
||
|
var lookRot =
|
||
|
dirVector == Vector3.zero
|
||
|
? Quaternion.identity
|
||
|
: Quaternion.LookRotation(dirVector); //get our look rot to the target
|
||
|
|
||
|
//UPDATE ORIENTATION CUBE POS & ROT
|
||
|
transform.SetPositionAndRotation(rootBP.position, lookRot);
|
||
|
}
|
||
|
}
|
||
|
}
|