I got my gun to shoot but when I want to shoot an object that is close the player it doesn’t work.
I have no idea what is causing this so your help would be most appreciated.
here is my shooting JS
var range= 100.0;
var force=10.0;
private var hitParticles : ParticleEmitter;
function Start ()
{
hitParticles = GetComponentInChildren(ParticleEmitter);
if (hitParticles)
{
hitParticles.emit = false;
}
}
function Update ()
{
if( Input.GetButtonDown( "Fire1" ) )
{
var direction = transform.TransformDirection(Vector3.forward);
var hit : RaycastHit;
if (Physics.Raycast (transform.position, direction, hit, range))
{
if (hit.rigidbody)
{
hit.rigidbody.AddForceAtPosition(force * direction, hit.point);
}
if (hitParticles)
{
hitParticles.transform.position = hit.point;
hitParticles.transform.rotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
hitParticles.Emit();
}
}
}
}