I have used pythagoras to give the bullet a velocity in the bullet class. Velocity is applied when Instantiated();
private Rigidbody2D rB;
private Vector2 velocity;
private float bulletSpeed = 15f;
rB.velocity = new Vector2(bulletSpeed * (Mathf.Cos(transform.rotation.z)), bulletSpeed * (Mathf.Sin(transform.rotation.z)));
I call the instantiation from the Gun
class.
if (Input.GetButtonDown("Fire1"))
{
bullet = Instantiate(bullet, bulletObjectPos.transform.position, transform.rotation);
}
Its giving me funny velocities for the angle i shoot from when the placeholder Gameobject class is rotated, shown below:
Do i need to do more to the velocity? like conversions to radians or something? Or is doing the Pythagoras thing all wrong. I've been scouring the internet all day.Thanks for any help.
The 'Bullets' travel from the muzzle to their location on the images