Game Development Community

RayCast hitting an Item

by Mark Dynna · in Torque Game Engine Advanced · 07/12/2007 (8:40 pm) · 6 replies

I'm probably missing something obvious here, but I can't seem to get a RayCast to hit an Item object. I'm doing this so I can have the character pick up items by clicking on them. I've tried the item selection code from this resource. Beyond the exemption changes, it just uses the standard RayCast function. I also tried enabling the collision mesh on Items from this resource.

Every time the RayCast seems to go right through the item. Yes, I'm sure I have the collision masks set correctly. I've tried it with ShapeBaseObjectType and ItemObjectType. What am I missing?

#1
07/13/2007 (1:44 am)
Are you sure raycasts are actually hitting the item? stick a breakpoint in the item->raycast code?

If its in a parent class (which I think it is) make sure that trips.

It might be that raycasts dont hit items where as convex collisions do?

Another option, might be that its simply rendering in the wrong place so when you try and hit it, you arent actually aiming in the right place. Do you see any weirdness when you select it in the world editor?
#2
07/13/2007 (10:49 am)
There is no Item::castRay function. Is that the obvious part that I'm missing?
#3
07/13/2007 (12:22 pm)
Yes I think you are correct, you have to add it.
#4
07/19/2007 (7:56 am)
Ah, turns out it was nothing so complex. The Item needs a collision mesh to be hit by a raycast and since "stock" torque doesn't use them (Item collision meshes) most of them don't have one!
#5
07/19/2007 (12:19 pm)
Ahh I thought 'item' didnt have a raycast function, but they just need collision meshes, thats good to know for what I'm working on now. Thanks Mark.
#6
07/19/2007 (12:57 pm)
This being my first time of really diving into the Item code, however, I have concluded that it will need to be re-done for our purposes (an RPG game). Item was written for Tribes' purpose: a class for ammo boxes, and health packs. It's not really well suited for something like an RPG which relies heavily on Items and needs them to interact in a variety of ways. If I feel my re-written "RPGItem" class is good enough I may post it as a resource.