Question by
ReaperjTw · Jul 02, 2018 at 08:52 AM ·
2d gameshootingmouseposition
2d Shooting to Mouse position
Hello I need a quick help with my script .. I know there are already a few entries that handle this but somehow it does not work: S When I shoot a projectile, it always stops exactly at the position of the crosshairs, but I want the shot to continue and not stop at the position of the crosshairs. I'm currently totally on the hose and would be glad about a solution ..
public class Projectile : MonoBehaviour {
// Public
public float speed;
// Private
private Vector2 target;
// Use this for initialization
void Start () {
target = Camera.main.ScreenToWorldPoint (Input.mousePosition);
}
// Update is called once per frame
void Update () {
transform.position = Vector2.MoveTowards(transform.position, target, speed * Time.deltaTime);
}
}
Comment