您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
36 行
1.4 KiB
36 行
1.4 KiB
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 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);
|
|
}
|
|
public void UpdateOrientation(Vector3 pos, Vector3 dirVector)
|
|
{
|
|
// var dirVector = target.position - transform.position;
|
|
dirVector.y = 0; //flatten dir on the y. this will only work on level surfaces
|
|
var lookRot =
|
|
dirVector == Vector3.zero
|
|
? Quaternion.identity
|
|
: Quaternion.LookRotation(dirVector.normalized); //get our look rot to the target
|
|
|
|
//UPDATE ORIENTATION CUBE POS & ROT
|
|
transform.SetPositionAndRotation(pos, lookRot);
|
|
}
|
|
}
|
|
}
|