Jump to content
Sign in to follow this  
chris77

How can I detect if one object would collide with another?

Recommended Posts

When carrying an object using attachTo it is possible to place it partially or fully into another object and release it.

This almost always leads to violent bouncing and explosions of things that I would rather not have bounce around/explode.

Background information: I am working on a set of scripts that allow me to freely load vehicles. Grab something, walk up and into the vehicle (kyo's excellent MH-47E specifically) and put it down.

Through some mathemagics I will get the attachment point and fix the cargo to the transporter.

However since attached objects are somewhat transcendent it is possible to stack cargo inside each other. Also I could carry in objects that would not even fit through the cargo door. In order to prevent all of this I would need a means to check for collisions not relying on bounding boxes. They're much too coarse for this purpose.

I would probably need some kind of PhysX collision checking, I guess. Is this even possible? The Biki has functions for enabling and disabling collision checking which is nice, but not really what I am looking for. I also do not want to use hit/damage events because I want to prevent potential collisions in the first place.

Share this post


Link to post
Share on other sites

Thank you for your quick replies, Tajin and Killzone Kid.

Checking the bounding boxes for the cargo is not that difficult. It is just that they are always cubic so you cannot stack round objects like barrels densely. However I am willing to settle with that for sake of simplicity.

I have seen the EPE event handlers, however from the description I gather they fire when the collision is already happening. Good idea but unfortunately that would be too late.

The concave nature of the back of a truck or the interior of the MH-47 are the most difficult hurdle. I think a reasonable approach would be defining cargo area boxes with checks running against cargo in hand, cargo area and attached cargo bounding boxes. This would be somewhat more CPU-intensive. A PhysX-based collision detection would have been nice since it runs on the graphics card and all the data needed is already there. I am aiming for low performance impact and good MP performance. I probably need to scale back a little and not allow carried cargo inside the bounding boxes of vehicles and switch to automatic stowing of cargo using rasters of cargo positions in combination with individual bounding box checking when loading the cargo. This should cause no discernible performance impact while still allowing mixed cargo loading at the expense of cargo density since this approach does not always provide the tightest cargo packing.

And on a personal note: Thank you for your tutorials, Killzone Kid. They helped me a lot with understanding the inner workings of ArmA.

Share this post


Link to post
Share on other sites

There's 3 EPE eventhandlers, if I remember correctly. One activates when an epe event starts, another while it's going on and the last when the epe event ends. But I've not found them to be reliable and so used other methods of detecting collision.

Share this post


Link to post
Share on other sites

I am going with the last solution now. It is just simple linear Algebra. However the situation is complicated by the weapons/munitions/grenade/launchers/special boxes having disproportionally larger bounding boxes than their actual 3D models. I have collected the minimum and maximum vertices for more appropriate bounding boxes for placement checking:

\A3\weapons_F\AmmoBoxes\WpnsBox_long_F

[ -0.805605, -0.16573, -0.1892087 ]

[ 0.805605, 0.16573, 0.1892087 ]

\A3\weapons_F\AmmoBoxes\WpnsBox_large_F

[ -0.805605, -0.331085, -0.1892087 ]

[ 0.805605, 0.331085, 0.1892087 ]

\A3\weapons_F\AmmoBoxes\WpnsBox_F

[ -0.532798, -0.331085, -0.1892087 ]

[ 0.532798, 0.331085, 0.1892087 ]

\A3\weapons_F\AmmoBoxes\AmmoBox_F

[ -0.220985, -0.331085, -0.319649 ]

[ 0.220985, 0.331085, 0.319649 ]

Share this post


Link to post
Share on other sites

Nice work there, Chris.

Linear algebra might be simple to you! :) My solution was even simpler. I just got a distance between the main object and the nearest object and when it got below a determined level, I assumed collision. :)

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×