MovePosition功能在我的脚本中不起作用: 我试过让它变成keneitic并增加力量。我也尝试在检查员中添加速度。我尝试添加强制并使更新功能成为“FixedUpdate” 这是我的更新功能中的内容:
if (target != null)
{
Action(target);
GameObject TemporaryBulletHandler;
TemporaryBulletHandler = Instantiate(Sphere, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) as GameObject;
Rigidbody TemporaryRigidBody;
TemporaryRigidBody = TemporaryBulletHandler.GetComponent<Rigidbody>();
float step = speed * Time.deltaTime;
pos = Vector3.MoveTowards(transform.position, target.position, step);
TemporaryRigidBody.MovePosition(pos);
Destroy(TemporaryBulletHandler, 10.0f);
创建的球体不会移动。
答案 0 :(得分:1)
根据Unity Docs Rigidbody.MovePosition创建一个平滑的移动,因此需要在固定更新的每一帧上调用它。
统一文档中的示例:
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour {
public Vector3 teleportPoint;
public Rigidbody rb;
void Start() {
rb = GetComponent<Rigidbody>();
}
void FixedUpdate() {
rb.MovePosition(transform.position + transform.forward * Time.deltaTime);
}
}
如果你想要的是传送僵尸,你应该看一下Rigidbody.position
答案 1 :(得分:1)
您应该在bullet-prefab中应用一个脚本,并在该脚本的FixedUpdate方法中添加移动代码,以便每个项目符号自己处理其移动逻辑。
答案 2 :(得分:0)
if (target != null)
{
Action(target);
GameObject TemporaryBulletHandler;
TemporaryBulletHandler = Instantiate(Sphere, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) as GameObject;
Rigidbody TemporaryRigidBody;
TemporaryRigidBody = TemporaryBulletHandler.GetComponent<Rigidbody>();
float step = speed * Time.deltaTime;
TemporaryRigidBody.MovePosition ( transform.position +(target.position - transform.position ). normalized * step );
Destroy(TemporaryBulletHandler, 10.0f);