【发布时间】:2019-11-29 19:04:03
【问题描述】:
我要做跟踪器。 这是我团结一致的轨迹 Track image
我想在unity C#脚本方法void Update{}中逐步操作代码1~10, 但我找不到如何制作它。 我使用三角系统、Sin 和 Cos 制作旋转代码。
Rigidbody rigidbody;
public GameObject ball;
Vector3 P1 = new Vector3(-5, 1.5f, 25);
public float theta;
// Start is called before the first frame update
void Start()
{
rigidbody = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
ball.transform.position = Vector3.MoveTowards(transform.position, P1, 0.05f); // 1st move
if(theta <210) // 2nd rotation with trigonometic equations
{
theta += 1;
ball.transform.position = Rot(theta);
}
}
Vector3 Rot(float theta) // rotation by trigonometric equations
{
Vector3 P2;
P2.x = (3 * Mathf.Cos(theta * Mathf.PI / 180) - 3 * Mathf.Sin(theta * Mathf.PI / 180)) -8;
P2.y = 1.5f;
P2.z = (3 * Mathf.Sin(theta * Mathf.PI / 180) + 3 * Mathf.Cos(theta * Mathf.PI / 180)) + 22 ;
return P2;
}
如果我播放该代码,球就会扭曲到位置 P1 并立即开始旋转 我该如何使用它?
并且不能使用键盘或其他输入处理程序,只能由代码使用
【问题讨论】: