C# Unity 5.1相对于玩家对象的次要对象的玩家控制

C# Unity 5.1相对于玩家对象的次要对象的玩家控制,c#,unity3d,rotation,position,C#,Unity3d,Rotation,Position,我做了很多搜索,但找不到解决这个问题的方法 我想要的是控制一个游戏对象,该对象根据右模拟杆输入以固定距离围绕玩家对象旋转,与玩家移动无关。我还希望对象在围绕播放器移动时面朝外 我已将左侧模拟杆设置为播放器移动和工作,并将右侧模拟杆设置和测试,以便我知道输入正在工作 我试过transform.rotate、RotateAround、、position和quaternions等,但都没有找到任何有用的方法。我对这一点相当陌生,所以可能有一个简单的解决方案,我就是看不出来 感谢你能给予的任何帮助:)非

我做了很多搜索,但找不到解决这个问题的方法

我想要的是控制一个游戏对象,该对象根据右模拟杆输入以固定距离围绕玩家对象旋转,与玩家移动无关。我还希望对象在围绕播放器移动时面朝外

我已将左侧模拟杆设置为播放器移动和工作,并将右侧模拟杆设置和测试,以便我知道输入正在工作

我试过transform.rotate、RotateAround、、position和quaternions等,但都没有找到任何有用的方法。我对这一点相当陌生,所以可能有一个简单的解决方案,我就是看不出来

感谢你能给予的任何帮助:)非常感谢

编辑2:第二次尝试

到目前为止,我已经知道了:

public class ShieldMovement : MonoBehaviour {

public Transform target; //player shield is attaced to

float distance = 0.8f; // distance from player so it doesn't clip
Vector3 direction = Vector3.up;


// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {

    float angle = Mathf.Atan2 (Input.GetAxisRaw("rightH"), Input.GetAxisRaw("rightV"))* Mathf.Rad2Deg;

    if(Input.GetAxis("rightH") != 0f || Input.GetAxis("rightV") != 0f)
    {
        direction =  new Vector3(Input.GetAxis("rightH"),Input.GetAxis("rightV"), 0.0f ) ;
    }

    Ray ray = new Ray(target.position, direction);
    transform.position = ray.GetPoint(distance);

    if(Input.GetAxis("rightH") != 0f || Input.GetAxis("rightV") != 0f)
    {
        transform.rotation = Quaternion.AngleAxis(angle,Vector3.forward*-1);
    }


}
}

我希望它是一个平滑的旋转盾牌周围的球员去一个新的位置,而不是传送那里。我尝试了一些LERP和SLERP,到目前为止,我所能做的就是从圆周上的一个点直接插值到新的点。想不出一种方法让它像你旋转球杆那样绕着球员旋转。希望这有意义


你有什么好主意吗?

这里有两种方法可以实现你想要的

请注意:这尚未经过测试

使用自定义的标准化处理
0f
正是
Vector3.forward
1f
将您带回
Vector3.forward

使用
Input.GetAxis

using UnityEngine;
using System.Collections;

public class Follower : MonoBehaviour {

    float distance = 10f;
    Vector3 direction = Vector3.forward;
    float speed = .01f;
    Transform target;

    void Update() {
        direction *= Quaternion.AngleAxis(Input.GetAxis("Horizontal") * speed * Time.deltaTime, Vector3.up);
        Ray ray = new Ray(target.position, direction);

        transform.position = ray.GetPoint(distance);
        transform.LookAt(target);
    }
}

您是否已经查看了SmoothFollow相机脚本?它使摄像机以一定的角度和距离跟随玩家旋转面对他。您也可以调整跟随器对象,并在移动斗杆时增加位置(x、0、z)。我现在无法测试它,但查看脚本似乎是最终了解您需要做什么的一个好方法…我会检查它,谢谢:)如果它有效,将发布:)检查它,有点了解它的来源,但我似乎无法继续。我已经发布了一个没有动画的部分解决方案(因为我不能让那一点工作),如果你想看看我到目前为止得到了什么:)对我来说都不太有效,但我得到了第二个没有动画部分的解决方案,当你在棍子上指向那个方向时,它只会出现在正确的位置,会像我说的那样发布我的代码,我还没有测试过,但我确信解决方案就在代码的某个地方,只做了一些小的调整;)是的,非常有用,谢谢:)我还在努力:)
using UnityEngine;
using System.Collections;

public class Follower : MonoBehaviour {

    float distance = 10f;
    Vector3 direction = Vector3.forward;
    float speed = .01f;
    Transform target;

    void Update() {
        direction *= Quaternion.AngleAxis(Input.GetAxis("Horizontal") * speed * Time.deltaTime, Vector3.up);
        Ray ray = new Ray(target.position, direction);

        transform.position = ray.GetPoint(distance);
        transform.LookAt(target);
    }
}