Game Development Community

Detecting objects with ContainerRayCast?

by Rubes · in Torque Game Engine · 02/11/2006 (4:22 pm) · 10 replies

I'm using a simple routine for object selection (developed from the Object Selection resource), which uses a call to ContainerRayCast to find whichever object lies directly in the line of sight (in the crosshairs).

This method has worked beautifully and without flaw, until now.

I introduced a new object model into my game, which is a simple coin. Just a small cylinder with a box for a collision box. The collision box is working appropriately, as I can collide with it from all sides. But the ContainerRayCast method refuses to see the object no matter what I do.

I think the problem has to do with the DTS object itself, because (1) I can substitute the coin DTS model with another working DTS model in my code and the object is selected appropriately, and (2) I can replace a working DTS model with the coin DTS model in my code and it will no longer work.

But how can this be? Calls to ContainerRadiusSearch do return the coin appropriately, but ContainerRayCast can't see it. The modeller I'm working with has made the coin DTS model three different times now, all with working collision boxes, but none of them work. What are we missing?

#1
02/11/2006 (6:29 pm)
Does Torque list any warnings about the model when it is loaded?

If it is extremely small it might possibly cause some problems (though I can't see why myself).

A couple of suggestions: Try adding a LOS collision box to the model. Shouldn't be needed, but hey, you've tried everything else right?

You could also try oversizing the regular collision box. If it is really small this could help. Remind your modeler that the bounds needs to enclose every part of the dts(assuming he is using a package that requires manual bounds creation).

Oh yeah, one other thing, the collision mesh needs to be named "Col-1" exactly.
#2
02/11/2006 (9:38 pm)
Thanks, Martin. No, no warnings show up in the console. It's a very small model, but even scaling it up to a large size doesn't help. The modeler has made other objects without any problems, and I'm pretty sure the collision box on the coin is appropriate in size and position.

I'll look into the LOS collision box, but we're definitely stumped on this one.
#3
02/12/2006 (3:39 am)
Single step through the ray cast code for the object and see what it's doing. That will very quickly tell you if it's not getting collision geometry, if it's getting invalid geometry, a bug in the code, precision issues, etc. etc.
#4
02/12/2006 (11:09 am)
BTW, what class of object is the coin?
#5
02/12/2006 (12:12 pm)
@Ben: Thanks, I'll give it a try...

@Martin: It's an Item/ItemData object. All of our other objects are the same and work fine; the code for the coin is essentially duplicated from the others.
#6
02/12/2006 (12:56 pm)
Martin:
You might be on the right track when you ask about the size of the object. I had trouble getting accurate xyz hit locations for raycasts on small objects, it turned out to be due to rounding errors: I think the raycast results are clipped at only a couple of decimal places.
#7
02/12/2006 (12:59 pm)
I did try scaling the coin up to a much larger size, but that didn't work. I'm not sure if that also scaled the collision box, but I'm pretty sure it does.
#8
02/12/2006 (1:05 pm)
Did you try scaling it in the modelling program ?
#9
02/12/2006 (1:09 pm)
Not personally, but I'll get the modeller to give it a try.
#10
02/22/2006 (2:40 pm)
Just as an update, it looks like the collision box was too small. After making it larger, all's well.