Wednesday, June 3, 2015

P2D3

Managed to have the projectile firing at mouse location.  Feels a bit floaty at the moment though.

Next goal: add a static target killable by this projectile.

Note: considering the slower firing rate by design, it might be good to have a "charge up" animation attached to him to indicate cooldown.



Did so by defining instantiate angle from Player_Control, and adding a force to the "right" direction in projectile script.

rb.AddForce (transform.right * projAcce);

Learned that if I toggled on "is Kenetic" on the projectile, AddForce would not work to make it move.  Presumeably, the Kenetic checkbox turns on and off its physics in some way.

Quaternion.identity means rotation: default.

There is no "forward" for rigidbody 2D, rather "transform.right" for x and "transform.up" for y.

Screen position is different from world position, so in calculating mouse-aiming angle, mouse position needs to be translated into world position which transforms use.

Time to brush up on basic geometry :P

playerPos = transform.position;
            mousePos = Camera.main.ScreenToWorldPoint (Input.mousePosition);
            Vector2 dir = mousePos - playerPos;
            float angle = Mathf.Atan2(dir.y, dir.x)*Mathf.Rad2Deg;
            Instantiate(projectile1, transform.position, Quaternion.AngleAxis(angle,Vector3.forward));

No comments:

Post a Comment