Is it possible to have one way collisions? I thinking of a a typical platform game where the characters can pass through a platform while going up, but land on top of it going down.
If it isn't supported directly by bullet, then does anyone have a good efficient solution. My first guess is to set the characters collision filter mask based on the current Y velocity.
Thanks,
~GameQ
One way collision meshes?
-
- Posts: 1
- Joined: Wed Nov 11, 2009 9:32 pm
Re: One way collision meshes?
The filter mask is a good idea if the object you are moving is dynamic. Have you implemented it that way, or found a better solution?
I am currently trying to do this with a kinematic object. I am using sweep checks and ignoring certain types of collision based on my object's y-velocity.
Does anybody know of any other way of setting up a one-way collison other than dyamic/mask or kinematic/manual sweep-checks?
-scott
I am currently trying to do this with a kinematic object. I am using sweep checks and ignoring certain types of collision based on my object's y-velocity.
Does anybody know of any other way of setting up a one-way collison other than dyamic/mask or kinematic/manual sweep-checks?
-scott
-
- Posts: 508
- Joined: Fri May 30, 2008 2:51 am
- Location: Ossining, New York
Re: One way collision meshes?
Here's some code i use to do this for gimpact meshes. It hasn't killed anyone yet.
The idea is that the triangles are one-way, so that you don't get objects rattling around inside your vehicle body.
Code: Select all
121 void process_contact (btManifoldPoint& cp,
122 const btCollisionObject* colObj,
123 int partId, int index, bool gimpact)
124 {
125 (void) partId;
126 (void) index;
127 const btCollisionShape *shape = colObj->getCollisionShape();
128
129 if (shape->getShapeType() != TRIANGLE_SHAPE_PROXYTYPE) return;
130 const btTriangleShape *tshape =
131 static_cast<const btTriangleShape*>(colObj->getCollisionShape());
132
133
134 const btCollisionShape *parent = colObj->getRootCollisionShape();
135 if (parent == NULL) return;
136
137
138 btVector3 normal;
139 tshape->calcNormal(normal);
140
141 const btMatrix3x3 &orient =
142 colObj->getWorldTransform().getBasis();
143
144 normal = orient * normal;
145
146 btScalar dot = normal.dot(cp.m_normalWorldOnB);
147
148
149 if (gimpact) {
150 if (parent->getShapeType()==GIMPACT_SHAPE_PROXYTYPE) {
151 if (dot > 0) {
152 cp.m_normalWorldOnB -= 2 * dot * normal;
153 }
154 }
155 } else {
156 if (parent->getShapeType()==TRIANGLE_MESH_SHAPE_PROXYTYPE) {
157
158 btScalar magnitude = cp.m_normalWorldOnB.length();
159 normal *= dot > 0 ? magnitude : -magnitude;
160
161 cp.m_normalWorldOnB = normal;
162
163 }
164 }
165
166 }
167
168 bool contact_added_callback (btManifoldPoint& cp,
169 const btCollisionObject* colObj0,
170 int partId0, int index0,
171 const btCollisionObject* colObj1,
172 int partId1, int index1)
173 {
174 (void) colObj1;
175 (void) partId1;
176 (void) index1;
177 // 0 is always the gimpact?
178 // 1 is always the scenery?
179 process_contact(cp, colObj0, partId0, index0, true);
180 process_contact(cp, colObj1, partId1, index1, false);
181 //std::cout << to_ogre(cp.m_normalWorldOnB) << std::endl;
182 return true;
183 }
Last edited by sparkprime on Thu Nov 12, 2009 7:16 am, edited 1 time in total.
-
- Posts: 508
- Joined: Fri May 30, 2008 2:51 am
- Location: Ossining, New York
Re: One way collision meshes?
Note, this also contains the 'bumpy triangle mesh' fix, search forums for more info