我正在构建一个AR平台游戏测试并且有一个特定的问题,即约束角色运动围绕中心枢轴点以圆周运动旋转。
目前,该等级沿着x空间沿着长线构建,因此角色移动仅限于与左/右控制相关联的X移动,加上一个允许他明显跳跃的跳跃按钮,因此3D空间基本上是2D运动。因此,当玩家在水平中移动时,玩家必须走在并跟随X空间中的角色移动。
但是,我想构建一个级别为圆形的版本,并围绕播放器,这样他们就可以旋转身体以跟踪角色的移动。我查看了很多其他论坛帖子,但无法弄清楚如何将它们应用到我的特定角色设置中。
我已经调查过的一些想法或事情:
想知道是否有一个简单的育儿解决方案,其中角色是空游戏对象的父级,并调整我的playerController脚本以控制游戏对象的旋转与角色的方向。
< / LI>对rotateAround进行了一些研究,但我并不完全理解这个概念。
如果提供更多上下文,则粘贴当前播放器控制器代码。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class PlayerController : MonoBehaviour
{
//Movement
public float speed = 10, jumpVelocity = 10;
public LayerMask playerMask;
public bool canMoveInAir = true;
public AudioSource[] AudioClips = null;
//Combat
public int health =3;
public float invincibleTimeAfterHurt = 2;
//Teleporation
//public Transform destination01;
//public Transform destination02;
//public Transform destination03;
//References
private gameMaster gm;
Transform myTrans, tagGround;
Rigidbody myBody;
//GetComponent<Rigidbody> myBody;
bool isGrounded = false;
float hInput;
AnimatorController myAnim;
void Start ()
{
myBody = this.GetComponent<Rigidbody>();
myTrans = this.transform;
tagGround = GameObject.Find (this.name + "/tag_ground").transform;
myAnim = AnimatorController.instance;
gm = GameObject.FindGameObjectWithTag ("gameMaster").GetComponent<gameMaster> ();
}
void FixedUpdate ()
{
isGrounded = Physics.Linecast (myTrans.position, tagGround.position, playerMask);
myAnim.UpdateIsGrounded (isGrounded);
#if !UNITY_ANDROID && !UNITY_IPHONE || UNITY_EDITOR
Move (Input.GetAxisRaw("Horizontal"));
myAnim.UpdateSpeed(hInput);
if (Input.GetButtonDown ("Jump"))
Jump ();
//GetComponent<AudioSource>().Play();
#endif
Move (hInput);
}
void Move(float horizontalInput)
{
if (!canMoveInAir && !isGrounded)
return;
Vector3 moveVel = myBody.velocity;
moveVel.x = horizontalInput * speed;
myBody.velocity = moveVel;
}
public void Jump()
{
if(isGrounded)
myBody.velocity += jumpVelocity * Vector3.up;
if (!AudioClips[1].isPlaying)
{
AudioClips[1].Play();
}
}
public void StartMoving (float horizontalInput)
{
hInput = horizontalInput;
myAnim.UpdateSpeed(horizontalInput);
}
void Hurt()
{
health--;
if (health <= 0)
//SceneManager.LoadScene (SceneManager.LoadedScene):
//Application.LoadLevel (Application.loadedLevel);
SceneManager.LoadScene("UnityARKitMario13", LoadSceneMode.Single);
else
myAnim.TriggerHurt (invincibleTimeAfterHurt);
}
void OnCollisionEnter (Collision collision)
{
Enemy enemy = collision.collider.GetComponent<Enemy> ();
if (enemy != null) {
if (!AudioClips[0].isPlaying)
{
AudioClips[0].Play();
}
foreach (ContactPoint point in collision.contacts) {
Debug.Log (point.normal);
Debug.DrawLine (point.point, point.point + point.normal, Color.red, 10);
if (point.normal.y >= 1f) {
Vector3 velocity = myBody.velocity;
velocity.y = jumpVelocity;
myBody.velocity = velocity;
enemy.Hurt ();
} else {
Hurt ();
}
}
}
}
void OnTriggerEnter (Collider collision)
{
if (collision.CompareTag ("Coin")) {
Destroy (collision.gameObject);
gm.points += 1;
if (!AudioClips [2].isPlaying) {
AudioClips [2].Play ();
}
}
}
}