Im creating a top-down 2D shooter game.
I want my weapons to not shoot perfectly where I aim, but rather have a public float precision
that goes from 0 to 100.
Bullets then have a random side deviation from a minimum angle to a maximum angle based on the precision amount. And the bullet should also rotate accordingly based on shoot angle.
I’ve been trying to do this for days to almost no avail. I’m very new to Unity and don’t really understand how Quaternions and stuff work.
This is my code right now:
float lastFire;
public virtual void Fire()
{
if (Time.time > (lastFire + fireRate))
{
var bullet = Instantiate(bulletPrefab, firePoint.position, firePoint.rotation);
var rb = bullet.GetComponent<Rigidbody2D>();
// Shoot bullet
rb.AddForce(firePoint.right * projectileSpeed, ForceMode2D.Impulse);
lastFire = Time.time;
}
Any ideas?