首页 > 解决方案 > 向对象添加表示方向的向量

问题描述

我正在尝试使用传送制作一个简单的 VR 运动脚本。我用三个空GameObjects来生成 Quadratic BezzierCurvep0GameObject内线球员;它随着播放器移动。我的问题是点(Gameobjects)与玩家无关。当p0在 position0, 0, 0时,脚本工作正常;但是当我将它连接到播放器并在场景中移动播放器时,这些点与播放器无关。我想我搞砸了一些基本的东西。

using UnityEngine;

public class settingPos : MonoBehaviour 
{
    public Transform tf;
    public GameObject p0, p1, p2; 

    // 3 empty GameObjects to paste them into QuadraticBezzier Script which uses it for 
    // generate bezzier curve. p0 is gameObject inside player, it is moving with player

    public float UpForce; //simply value for scaling Bezzier curve
    Vector3 [] dir= new Vector3[2];

    void Update () 
    {

        dir[0] = p0.transform.position;
        Vector3 temp = transform.rotation * Vector3.forward;
        temp *= UpForce;
        dir[0] += temp;

        dir[1] = new Vector3(dir[0].x * 2, 0, dir[0].z * 2); // This is end point of bezzier 
                                                             // curve. I mentioned that 
                                                             // distance between end-point 
                                                             // and height of bezzier curve 
                                                             // was this same as start-point 
                                                             // and height.

        p1.transform.position = dir[0];
        p2.transform.position = dir[1];
    }
}

很短

它应该看起来一样,但在其他位置。

这显示了我的问题

标签: c#unity3dbezier

解决方案


推荐阅读