I’ve read a number of posts but can’t quite see what I’m doing.
So I’m shooting a ray at an object on fire1 and on a hit, instantiating a small projectile which will “pop” out a little way toward the shooter. So the script works and the object instantiates but just drops to the floor rather that shooting a little way back along the opposite direction. Thanks guys, great product and hours of fun and frustration :}
#pragma strict
var bang : Rigidbody;
private var x = Screen.width / 2;
private var y = Screen.height / 2;
function Update () {
var hit : RaycastHit;
if(Input.GetButtonUp("Fire1"))
{
// look for something to hit
var ray : Ray = Camera.main.ScreenPointToRay(Vector3(x, y,0));
if (Physics.Raycast (ray, hit, 100))
{
// make a projectile
Instantiate(bang, hit.point, Quaternion.LookRotation(hit.normal));
// bounce back a bit
bang.rigidbody.AddForce(transform.forward * -25);
}
}
}