Hiya,
I’m trying to make it so that I can pick up an object using raycasting in a FPS. This is the code I have so far, I attach it to the Main Camera in the First Person Controller, and have added a box collider to the object I wish to be interacted with.
var rayCastLength = 5;
function Update ()
{
var hit : RaycastHit;
if (Physics.Raycast(transform.position, transform.forward, hit, rayCastLength))
{
if(hit.collider.gameObject.tag == "ID")
{
hit.collider.gameObject.Destroy();
}
}
}
Umm I’m sure you’re right, but I should have mentioned I’m new to this! So what line am I replacing with that?
And thanks for the quick response!
Ok thanks, I tried it but it still isn’t working. The object remains where it is.
Ok thank you, it says it Hit the terrain, but not the object I wish to interact with.
PS. Thanks for your patience! I know I’m new to this and annoying but I’m trying!
I put it outside the if loops. And I just made sure the tag was set properly and it is now hitting the object, but no action happens after that.
Ok I put it inside the first if loop. The tag of the object is IDCard. When I set the condition to check for the tag to IDCard, the console never shows that it Hit: IDCard. But when I set the condition to ID it does show the Hit: IDCard.
Either way though, the IDCard never gets destroyed. (I realise I was unclear, I don’t want it literally picked up. I’m hoping to get it so that when you move over it and either press a button or not, it’s considered found and then when opening a door later, the check returns true and allows the door to open)