Shooting prefab according to cannon angle with projection

178 views Asked by At

This code shoots at the mouse pointer but goes directly, not by projection. I need it to be like the picture below.

var prefab : GameObject;
function Update () {
    if (Input.GetMouseButtonDown(0)) {
        var pos = Input.mousePosition;
        pos.z = transform.position.z - Camera.main.transform.position.z;
        pos = Camera.main.ScreenToWorldPoint(pos);
        var q = Quaternion.FromToRotation(Vector3.up, pos - transform.position);
        var go = Instantiate(prefab, transform.position, q);
        go.rigidbody2D.AddForce(go.transform.up * 20000.0);  
    }
}

0

There are 0 answers