Game Development Community

Editing Collision Polygon

by Doug Barnes · in Torque X 2D · 11/20/2007 (9:04 am) · 4 replies

Hello everyone,

I was wondering if it is possible to edit a scene objects collision polygon through code, and if so how do you do it? The reason I want to change the collision polygon is so when a character is crouching the collision box wont be the same size as if they were still standing.

thanks in advance,
Doug

#1
11/20/2007 (7:42 pm)
Hi Doug,

I've been playing around with this tonight, and heres what I've found out. The collision polygons for an object are stored in a readonly list of T2DPolyImages at SceneObject.Collision.Images. You can manage that list with SceneObject.Collision.InstallImage() and SceneObject.Collision.RemoveImage(). Each T2dPolyImage has an array of Vector2s that represents the polygon called CollisionPolyBias. The X and Y members of these vectors are have values or -1 to 1.

I haven't tried it out yet, but here's how it envision it working.

Change animation data
Play animation (not sure if this should go here or at the end, probably doesn't matter)
Call RemoveImage(Collision.Images[0])
Create a new T2dPolyImage, img, and fill the CollisionPolyBias array with Vector2s
Call InstallImage(img)

After reading through the source, it seems you can 'Install' multiple collision images to make more complex collision shapes. As far as I know TBX limits you to one collision poly.
#2
11/21/2007 (7:49 am)
Thanks a lot Joshua,

I managed to get it working quite quickly with your help. I tried implementing it just as you explained and you were dead on it worked flawlessly.

thanks again,
Doug
#3
11/21/2007 (12:25 pm)
Nice! I'm kinda excited. We can probably animate the colision poly(s) if we need to.
#4
08/31/2009 (10:12 pm)
Hi!!!

Is it possible to post some code sample to do this?

I need to load my collisionpoints from file, and need to change it through code!

Thanks!