- Home /
Question by
ObviouslyInsane · Aug 21, 2011 at 09:35 PM ·
raycastcolliderlayercollide
Raycast not colliding with selected layer
Hi everyone, I have this script here:
var linePrefab : GameObject;
var hitPrefab : GameObject;
var layerMask = 1 << 8;
var range = 0.00;
var damage = 0.00;
//var randomstart =0.00;
//var randomstop = 0.00;
private var hit : RaycastHit;
function Update(){
if(Input.GetButtonDown("Fire1")){
Shoot();
}
//var randomstart = Random.Range( 5.0, 14.0);
//var randomstop = Random.Range(28.0, 800.0);
}
function Shoot ()
{
newLineObject = Instantiate(linePrefab);
newLine = newLineObject.GetComponent(LineRenderer);
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));
hit.layerMask.collider.gameObject.SendMessage("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
}
else
{
newLine.SetPosition(0, transform.position);
newLine.SetPosition(1, transform.TransformPoint(Vector3.forward * range));
}
}
As you can see it creates a LineRenderer which ignores all layers except the one I specified. That all works fine except it isn't colliding with the specified layer. Can someone give me an idea how to fix this?
Comment
Your answer
Follow this Question
Related Questions
Lag when I change the layer of a game object ingame 0 Answers
LayerMask for RayCast 1 Answer
Is it possible to allow a raycast to pass through a collider to hit things behind it? 6 Answers
collider.Raycast problem 2 Answers
Get collider from raycast 4 Answers