gpt4 book ai didi

graphics - 如何使从物体发射的弹丸移向 Unity3d 中的特定点?

转载 作者:行者123 更新时间:2023-12-04 05:15:36 26 4
gpt4 key购买 nike

我有一个移动的物体,当你按下 shift 键时它会从它发射出一个射弹

我希望我的弹丸移动到特定点 (0,0,10)

我已经尝试了以下代码,但它不起作用

if (Input.GetKey("right shift")||Input.GetKey("left shift")) {
Rigidbody clone;
clone = Instantiate(projectile1, transform.position, transform.rotation) as Rigidbody;
clone.velocity=new Vector3(0,0,10);

有人可以帮忙吗?

最佳答案

如果您想要恒定速度,请改用 MoveTowards:MoveTowards(pointA, pointB, delta) 返回点 A-pointB 距离点 A 距离增量单位的线中的一个点 - 并固定到点 B,因此它永远不会超出目标点。

if (Input.GetKey("right shift")||Input.GetKey("left shift")) {
Rigidbody clone;
clone = Instantiate(projectile1, transform.position, transform.rotation) as Rigidbody;
clone.position = Vector3.MoveTowards(transform.position, new Vector3(0,0,10), Time.deltaTime * speed); }

其中速度以米(或单位)每秒为单位。

关于graphics - 如何使从物体发射的弹丸移向 Unity3d 中的特定点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14309669/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com