是否可以将游戏对象移动到单位2D中的单击位置,而游戏对象是具有重力的刚体2d,并且移动看起来像从游戏对象的位置跳到点击位置。任何帮助参考都会非常有用:)
答案 0 :(得分:2)
Transform projectile;
float speed = 5f;
void Update()
{
if(Input.GetMouseButtonDown(0))
{
Vector3 target = Camera.main.ScreenToWorldPoint(Input.mousePosition);
target.z = projectile.position.z;
Vector3 offset = target - projectile.position;
Vector3 direction = offset.normalized;
float power = offset.magnitude;
projectile.GetComponent<RigidBody2D>().AddForce(direction * power * speed);
}
}