1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

2Dシューティングの備忘録

Posted at

クリックした位置に弾を飛ばす

        var v = Input.mousePosition;
        v.z = transform.position.z - Camera.main.transform.position.z;
        var worldVector3 = Camera.main.ScreenToWorldPoint(v);
        worldVector3.x += -mEmitter.transform.position.x;
        worldVector3.y += -mEmitter.transform.position.y;

        var bullet = (GameObject)Instantiate(mBulletPrefab, mEmitter.transform.position, Quaternion.identity);

        var rad = Mathf.Atan2(worldVector3.y, worldVector3.x);
        var vx = Mathf.Cos(rad);
        var vy = Mathf.Sin(rad);

        bullet.rigidbody2D.velocity = new Vector2(MoveSpeed * vx, MoveSpeed * vy);
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?