- Home /
raycast doesnt seem to collide
i cant seem to get my door to animate upon raycast collide the script is attached ot my fps controller heres my script.
var rayLength = 6;
function update ()
{
var hit = RaycastHit;
if(Physics.raycast(transform.position, transform.forward, hit, rayLength))
{
if(hit.collider.gameObject.tag == "door")
{
hit.collider.gameObject.animation.Play("door_open");
}
}
}
Do you get any errors in the log? What happens when you get close to the door?
no errors in the log, also when i approach the door nothing happens. might be worth mentioning but i tried making it open on colliding with my fps controller and it works fine.
Is the door in a special layer? And is it possible for the ray layer to collide with the door layer?
Answer by whydoidoit · Jul 11, 2012 at 01:47 PM
You have called your function update() but it needs to be called Update() or it won't be called by Unity.
That's because it is Raycast (not raycast) - you really need to watch your capital letters - the language is case sensitive.
Ok update fixed one issue now it seems it doesnt like my string
"if(Physics.raycast(transform.position, transform.forward, hit, rayLength))" any ideas?
i retyped it wrong on here after i fixed my it to Raycast sorry for that internets being really weird today still not accepting my string getting the error :
No appropriate version of 'UnityEngine.Physics.Raycast' for the argument list '(UnityEngine.Vector3, UnityEngine.Vector3, System.Type, int)' was found.
Your answer
![](https://koobas.hobune.stream/wayback/20220613074031im_/https://answers.unity.com/themes/thub/images/avi.jpg)