做了个导弹的模型,需要设置加力发射或者速度发射,所以整理了下代码备忘
if (isAddForceLaunch)
{//加力发射
GetComponent<ConstantForce2D>().relativeForce = new Vector2(0, StartForce);
}
else
{//速度发射
float angles = (transform.parent.eulerAngles.z + 90) % 360 * Mathf.Deg2Rad;
Vector2 velocity = new Vector2(Mathf.Cos(angles), Mathf.Sin(angles));
GetComponent<Rigidbody2D>().velocity = velocity.normalized * StartForce;
}