Game Development Community

More than one collision poly per object?

by Matt Sayre · in Torque Game Builder · 03/12/2005 (9:59 am) · 4 replies

Is there any way to get more than one custom collision poly per object? I've got an object where I want two small collision boxes, one in the upper left, one in the lower left, and I have no idea how to do this, or if it's possible.

I know how to solve the problem if it's not possible. I'll just cut the sprite in half and mount one to the other so each half has the one collision box. But I thought there might be a simpler non-art way.

thanks!

#1
03/12/2005 (11:11 am)
I've also been thinking about this, specially for concave-shaped objects, and I think having mounted objects is the way to go. I mean, your game object will contain:

- a StaticSprite with the image data and without a collision poly
- several SceneObjects without image and with collision poly, mounted to the sprite
#2
03/12/2005 (1:44 pm)
The only limitation I can think of is that physics might not operate correctly on a "compound" object like this.
#3
03/12/2005 (2:23 pm)
Matt, for right now, yes you'd have to do something like Manuel says. And Jason is correct too, you'll need to be careful about how you set-up your physics parameters when using sub-objects like this. (It's possible to get nice, realistic behavior using sub collision objects though).

Melv and I discussed early on the possibility of supporting multiple collision polys out of the gate, and/or supporting concave polygons (and/or pixel mask collisions). But we ultimately decided that supporting a single arbitrary convex poly w/ time-swept collisions would already offer better and faster collision support than any other 2D engine. So, rather than making everyone wait for us to implement more collision schemes, we decided to release with the current system, especially since you can decompose an object into several convex sub-objects for now.

Seems like a good call. As for future collision support, I don't want to make any promises there just yet. Melv and I would both love to get time to implement more collision schemes, but we need to focus on tools, documentation, and more tech.

I'd love to see the T2D community generate some custom collision scheme implementations, we tried to write T2D such that creating your own systems would be as clear as possible. :)

So for now, your best bet is to use sub-objects, yep. However, you don't need to mess with your art to do it. You could use one single sprite / image w/ no collision on it, and then attach invisible sceneobjects with collision enabled to do the actual collision for the object.

You will get different physics if you are using the built-in rigid body sim this way, as the center points of the sub-objects won't be the same as the entire sprite, but sometimes this can actually lead to more realistic behavior.
#4
03/12/2005 (3:45 pm)
Sounds good, Josh. I can definitely live with that. If I can understand something, then it's great for me.

And Manuel, thanks! You certainly described a much better way to do it (using image-less scene objects mounted to the sprite). No cutting up of images... duhhh... :)

While we're on the subject of collisions, how to I get the physics to only react in one axis? I have a mouse that you can make jump up and down. If he hits something, I want him to either go straight up or down, not to the side at all. So how can I turn off the x-axis? Seems like I'm missing something obvious.

-- ah ha, nevermind... I just set the world limit for the mouse so that it couldn't move left or right:

$mouse.setWorldLimit( rigid, "-37 -37 -24 17" );

:)