I know this is a probably incredibly noob-ish question, but is it possible to have bulletspread with a rigidbody that is controlled using Raycast triangulation?
Here is an example of the script I am using:
#pragma strict
var spawnPoint: Transform;
var projectileSpeed: float = 20;
var projectilePrefab: Transform;
function Update () {
if (Input.GetButtonDown("Fire1")){
var ray: Ray = Camera.main.ViewportPointToRay(Vector3(0.5,0.5,0));
var hit: RaycastHit;
var dir: Vector3;
Debug.DrawRay(ray.origin, ray.direction * 1000, Color.yellow);
if (Physics.Raycast(ray, hit)){
dir = (hit.point - spawnPoint.position).normalized;
}
else {
dir = ray.direction;
}
var rot = Quaternion.FromToRotation(projectilePrefab.forward, dir);
var projectile = Instantiate(projectilePrefab, spawnPoint.position, rot);
projectile.rigidbody.velocity = dir * projectileSpeed;
}
}
If there isn’t a way, then is it possible to triangulate two raycasts instead of a raycast and a rigidbody?
Thanks so much in advance.