Hi, so I found a script that allows me to instantiate a projectile object that aims toward mouse position. However I want to modify it to instantiate three projectiles, one directly toward mouse position and two more from the same starting point but with one being at an increase of angle and one being at a decrease. You can think of it like this.
Normal Projectile: –
/
New Projectile —
\
I have the script that I’m currently using attached below.
using UnityEngine;
public class SwordShot : MonoBehaviour
{
public GameObject bullet;
public Transform firePoint;
public float bulletSpeed = 50;
Vector2 lookDirection;
Vector2 lookDirection2;
float lookAngle;
public Camera cam;
public float shootCD;
public float timeSinceLastShot;
void Update()
{
lookDirection = cam.ScreenToWorldPoint(Input.mousePosition);
lookDirection2 = new Vector2(lookDirection.x - transform.position.x, lookDirection.y - transform.position.y);
lookAngle = Mathf.Atan2(lookDirection2.y, lookDirection2.x) * Mathf.Rad2Deg;
firePoint.rotation = Quaternion.Euler(0, 0, lookAngle);
if (Input.GetKeyDown(KeyCode.F) && timeSinceLastShot <= 0)
{
timeSinceLastShot = shootCD;
GameObject bulletClone = Instantiate(bullet);
bulletClone.transform.position = firePoint.position;
bulletClone.transform.rotation = Quaternion.Euler(0, 0, lookAngle - 90);
bulletClone.GetComponent<Rigidbody2D>().velocity = firePoint.right * bulletSpeed;
Destroy(bulletClone, .71f);
}
if (timeSinceLastShot > 0)
{
timeSinceLastShot -= Time.deltaTime;
}
}
}