Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使台球杆围绕主球旋转?_C#_Unity3d_Game Physics - Fatal编程技术网

C# 如何使台球杆围绕主球旋转?

C# 如何使台球杆围绕主球旋转?,c#,unity3d,game-physics,C#,Unity3d,Game Physics,我希望当球员拖动鼠标时,台球杆围绕主球旋转,我在互联网上玩过一些台球游戏,它们似乎都是这样工作的。这将最终成为一款浏览器游戏 这个游戏不是我的,但它有我想要的基本机制(我不在乎显示的线条,我只想要旋转和击球机制) 到目前为止,我已经尝试了一些轨道脚本,但都不起作用 我尝试了一些脚本,使对象基于时间运行,希望通过鼠标拖动而不是时间来运行。我也不能让球杆一直面对主球 这个密码让我最接近了 public int vertexCount = 40; public float lineWidth

我希望当球员拖动鼠标时,台球杆围绕主球旋转,我在互联网上玩过一些台球游戏,它们似乎都是这样工作的。这将最终成为一款浏览器游戏

这个游戏不是我的,但它有我想要的基本机制(我不在乎显示的线条,我只想要旋转和击球机制)

到目前为止,我已经尝试了一些轨道脚本,但都不起作用

我尝试了一些脚本,使对象基于时间运行,希望通过鼠标拖动而不是时间来运行。我也不能让球杆一直面对主球

这个密码让我最接近了

public int vertexCount = 40;
    public float lineWidth = 0.2f;
    public float radius;
    public bool circleFillscreen;
    //circle variables
    static float timeCounter = 0;
    float width;
    float height;

    private LineRenderer lineRenderer;

    private void Awake()
    {
        lineRenderer = GetComponent<LineRenderer>();
        SetupCircle();
    }

    void Update()
    {

        timeCounter += Time.deltaTime;

        float x = Mathf.Cos(timeCounter);
        float y = 0;
        float z = Mathf.Sin(timeCounter);



    }



    private void SetupCircle()
    {
        lineRenderer.widthMultiplier = lineWidth;

        if (circleFillscreen)
        {
            radius = Vector3.Distance(Camera.main.ScreenToWorldPoint(new Vector3(0f, Camera.main.pixelRect.yMax, 0f)),
                Camera.main.ScreenToWorldPoint(new Vector3(0f, Camera.main.pixelRect.yMin, 0f))) * 0.5f - lineWidth;
        }

        float deltaTheta = (2f * Mathf.PI) / vertexCount;
        float theta = 0F;

        lineRenderer.positionCount = -vertexCount;
        for (int i = 0; i < lineRenderer.positionCount; i++)
        {
            Vector3 pos = new Vector3(radius * Mathf.Cos(theta), radius * Mathf.Sin(theta), 0f);
            lineRenderer.SetPosition(i, pos);
            theta += deltaTheta;

        }



    }

#if UNITY_EDITOR
    private void OnDrawGizmos()
    {
        float deltaTheta = (2f * Mathf.PI) / vertexCount;
        float theta = 0f;

        Vector3 oldPos = Vector3.zero; 
        for (int i = 0; i < vertexCount + 1; i++)
        {
            Vector3 pos = new Vector3(radius * Mathf.Cos(theta), 0F,radius * Mathf.Sin(theta));
            Gizmos.DrawLine(oldPos, transform.position + pos);
            oldPos = transform.position + pos;

            theta += deltaTheta;

        }

    }
#endif

}
public int vertexCount=40;
公共浮点数线宽=0.2f;
公众浮标半径;
公共布尔环形荧光屏;
//循环变量
静态浮点计时器=0;
浮动宽度;
浮动高度;
专用线条渲染器线条渲染器;
私人空间
{
lineRenderer=GetComponent();
SetupCircle();
}
无效更新()
{
timeCounter+=Time.deltaTime;
浮点x=数学Cos(计时器);
浮动y=0;
float z=数学Sin(计时器);
}
专用循环()
{
lineRenderer.Width乘数=线宽;
if(圆形填充屏幕)
{
半径=矢量3.距离(Camera.main.ScreenToWorldPoint(新矢量3(0f,Camera.main.pixelRect.yMax,0f)),
Camera.main.ScreenToWorldPoint(新的Vector3(0f,Camera.main.pixelRect.yMin,0f))*0.5f-线宽;
}
浮点deltaTheta=(2f*Mathf.PI)/vertexCount;
浮动θ=0F;
lineRenderer.positionCount=-vertexCount;
对于(int i=0;i

没有收到任何错误消息,代码“起作用”但不起作用。

聪明的家长。一个空的游戏物体会创造奇迹。聪明的父母。一个空的游戏对象会创造奇迹。