Download

Need to limit a raytrace to only hit objects overlapping a trigger volume.

So, I am currently making a game with drivable boats using the built in wheeled vehicle setup. For the most part, everything has gone rather smoothly. I have recently run into a problem of the raytraces for the wheels catching on things I don’t want them to catch on. I tried changing the start point of those raytraces, but since the value is only read at the beginning of the game, that doesn’t work. So, I figured I would limit what objects the raytrace would be able to hit. However, I don’t know how to do this. I do, however, think I know where the limiting factor should go. My question to all of you who know C++ is, what code do I need to put where to get this to work? I have no knowledge of C++ or of any coding whatsoever, so you will have to be a tad specific.

Here is a visual to help explain exactly what is the problem and what is my desired solution:

SolutionVisuals3partsmaller.jpg&stc=1

SolutionVisualssmaller.jpg&stc=1

And to make it easy to assign what objects are acting as the trigger volumes:

added_collision_object_menu_smaller.jpg&stc=1

Here is the location that I believe would be the right place to add…whatever code is needed to limit the raycast to hitting only overlapping objects. Maybe the objects would be put in an array on overlap or something? Anyway, the location of this code is in the PhysXVehicleManager.cpp

possibly_where_to_add_collision_to_raycasts_PhysXVehicleManagerCPPsmaller.jpg&stc=1

When it comes right down to it, lack of knowledge on how to fix this problem is all that is keeping me from proceeding forward with my game. I would be extremely grateful to anyone who would be able to help me out with this problem. :smiley:

This is a job for Collision Channels! Conveniently enough James Golding just wrote up a blog about these too…

I imagine you’ll have to create your own Vehicle Component that derives from the one you’re currently using, and find a way to pass in a collision channel to the PhysX wheel solver. Honestly, I’m not sure how to go about that last bit but I can’t imagine it’s too difficult.

If that’s not possible then it might be simpler to write your own ‘Boat Movement Component’. There’s probably quite a few examples out there of boat physics you could use.

Well, Jamsh, I had thought about using collision channels, and while enticing, I don’t think that will work without running into the same issues I am having now. If I only use collision channels, then, for example, if the player wanted to drive the boat under a bridge that they could also drive on, the wheel raycasts would still have a chance of catching on geometry above the boat and causing it to fly off. Currently, I have the Suspension Max Raise set to a value of 1000, so I would have to make sure that my boat never got within 1000 units of the underside of any drivable surface. That would severly limit the number and placement of jumps and/or confined areas the player could drive in, and pretty much reduce how complex of a level I could create, and would probably be a nightmare for testing. Also, problems would probably arise whenever the boat would do a barrel roll, because the raycasts follow the local up direction of the boat, any drivable surface up to 1000 units to either side of the boat would catch hold of the wheels and cause a reaction. Unless there is a way to dynamically add and subtract meshes to collision channels on overlap, then I think my current solution is the optimal one.