I have a simple piece of code to take the angle of an object and move it at a vector based on that angle. Problem is, that is comes out at the wrong vector so some reason.
Code is:
void FireBullet() {
delayBullet = 0;
var bullet = (GameObject)Instantiate(bulletPrefab,
this.GetComponent<Transform>().position,
bulletPrefab.GetComponent<Transform>().rotation
);
Vector3 angles = bullet.GetComponent<Transform>().eulerAngles;
float rad = angles.z * Mathf.Deg2Rad;
Vector2 velocity;
velocity.x = Mathf.Cos(angles.z);
velocity.y = Mathf.Sin(angles.z);
bullet.GetComponent<Rigidbody2D>().AddForce(velocity * bulletSpeed);
}
Having the z angle of my bulletPrefab set to 90.0 degrees, ends up firing the projectile at about 110.0 degrees instead.