Hi everyone, I modified a rocket launcher script from the FPS tutorial to shoot a line renderer using raycasting. However, it isn’t colliding with the layermask I have specified. Can someone take a look at my code and see where I went wrong? Thank you.
var linePrefab : GameObject;
var hitPrefab : GameObject;
var range = 0.00;
var damage = 0.00;
var layerMask = 1 << 9;
var reloadTime = 0.5;
var ammoCount = 20;
private var hit : RaycastHit;
private var lastShot = -10.0;
function Fire () {
// Did the time exceed the reload time?
if (Time.time > reloadTime + lastShot && ammoCount > 0) {
// create a new projectile, use the same position and rotation as the Launcher.
newLineObject = Instantiate(linePrefab);
newLine = newLineObject.GetComponent(LineRenderer);
lastShot = Time.time;
ammoCount--;
}
if (Physics.Raycast (transform.position, Vector3.forward, Mathf.Infinity, layerMask))
{
newLine.SetPosition(0, transform.position);
newLine.SetPosition(1, hit.point);
if(hitPrefab) Instantiate(hitPrefab, hit.point, Quaternion.LookRotation(hit.normal));
Debug.Log("IVE BEEN HIT!!!!");
// if(LayerMask.NameToLayer(""));
hit.collider.gameObject.SendMessage("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
hit.collider.gameObject.GetComponent("PlayersHealth").curHealth -= 10;
Debug.Log("IVE BEEN HIT!!!!");
}
else
{
newLine.SetPosition(0, transform.position);
newLine.SetPosition(1, transform.TransformPoint(Vector3.forward * range));
}
}
As you can see it is supposed to collide with layer ‘9’, which I have specified as ‘Player’ and the debug statements I have set up aren’t being called at all.