Forums > Jitter

collision handing in javascript

February 27, 2012 | 5:04 am

Is there a more elegant javascript way to get the body1 and body2 subkeys from the collision dictionary?

In the example below, collision_names is an array containing all the collisions in which I’m interested. I create that array by concatenating the names of the two objects together in all permutations (ugh!). For any one of 10 objects hitting any one of 2 objects, that yields 40 potential names (10 x 2 x 2). It seems that Max doesn’t makes two collision names for the same two objects…but I don’t know which order that Max might concat it.

Once I have that array, then when I get the collision dictionary out of the right outlet of jit.phys.world, I send it to a js object containing this snippet of code…


function collisions()
{
var d = new Dict(arguments[1]);
var keys = d.getkeys();

for (var a=0; a
{
if (collision_names.indexOf(keys[a]) >= 0)
{
post(keys[a]);
post();
var subkeys = d.get(keys[a]);
for (asubkey in subkeys)
{
var subd = new Dict(subkeys[asubkey]);
post(subd.get("body1") + " hit " + subd.get("body2"));
post();
}
}
}
}


Viewing 1 post (of 1 total)