Question by
kodzhamanov · Jun 10, 2017 at 10:12 AM ·
shootingbullet
Bullet does not move forward
Any ideas? I've been struggling for a while now... There are no scripts attached to the bullet, there is a rigidbody2d with a dynamic setup.
public class BulletMove3 : MonoBehaviour { public GameObject bullet; public float speed = 5.0f;
// Use this for initialization
void Start () {
}
void Update () {
if (Input.GetMouseButtonDown(0)) {
Vector2 target = Camera.main.ScreenToWorldPoint( new Vector2(Input.mousePosition.x, Input.mousePosition.y) );
Vector2 myPos = new Vector2(transform.position.x+2,transform.position.y + 2);
Vector2 direction = target - myPos;
direction.Normalize();
Quaternion rotation = Quaternion.Euler( 0, 0, Mathf.Atan2 ( direction.y, direction.x ) * Mathf.Rad2Deg );
GameObject projectile = (GameObject) Instantiate( bullet, myPos, rotation);
projectile.GetComponent<Rigidbody2D>().velocity = direction * 5;
}
}
}
Comment