Collision Problem
BlitzMax Forums/MiniB3D Module/Collision Problem
| ||
Take a look at this vid. It shows the ball colliding with the hoarding and it gets stuck... http://download.newstargames.com/misc/NSS4/CollisionProb1.avi This example show the ball colliding with the rear of the hoarding and it rebounds in the wrong direction... http://download.newstargames.com/misc/NSS4/CollisionProb3.avi However, as you can see, if the ball bounces off the stadium wall it responds fine. This is also the case if I align the advert hoardings perfectly horizontal or verticle which makes me think it is a bug in minib3d. This is the code i'm using... Collisions(CTYPE_BALL, CTYPE_GOALNET, 2, 1) Collisions(CTYPE_BALL, CTYPE_GOALPOST, 2, 1) Collisions(CTYPE_BALL, CTYPE_WALL, 2, 1) Collisions(CTYPE_BALL, CTYPE_STADIUM, 2, 1) ' Hoardings use this. For Local i:Int = 1 To CountCollisions(mesh) Local ent:TEntity = CollisionEntity(mesh, i) Local Nx# = CollisionNX(mesh, 1) Local Ny# = CollisionNY(mesh, 1) Local Nz# = CollisionNZ(mesh, 1) Local VdotN# = vecVelocity.x*Nx# + vecVelocity.y*Ny# + vecVelocity.z*Nz# Local NFx# = -2.0 * Nx# * VdotN# Local NFy# = -2.0 * Ny# * VdotN# Local NFz# = -2.0 * Nz# * VdotN# Local bounce:Float = 0.8 vecVelocity.x = (vecVelocity.x + NFx#) * bounce vecVelocity.y = (vecVelocity.y + NFy#) * bounce vecVelocity.z = (vecVelocity.z + NFz#) * bounce Next Any idea? |
| ||
Hard to tell when your links are dead! |
| ||
Hmmm... Try changing the response mode to 2 (slide). Also try changing the loop as follows: For Local i:Int = 1 To CountCollisions(mesh) Local ent:TEntity = CollisionEntity(mesh, i) Local Nx# :+ CollisionNX(mesh, 1) Local Ny# :+ CollisionNY(mesh, 1) Local Nz# :+ CollisionNZ(mesh, 1) Next Local VdotN# = vecVelocity.x*Nx# + vecVelocity.y*Ny# + vecVelocity.z*Nz# Local NFx# = -2.0 * Nx# * VdotN# Local NFy# = -2.0 * Ny# * VdotN# Local NFz# = -2.0 * Nz# * VdotN# Local bounce:Float = 0.8 vecVelocity.x = (vecVelocity.x + NFx#) * bounce vecVelocity.y = (vecVelocity.y + NFy#) * bounce vecVelocity.z = (vecVelocity.z + NFz#) * bounceNot sure if either change will do anything but worth a try. |
| ||
Tried your code (after a little tweak, doesn't like Local Nx# :+) but no difference. Forgot to mention I'd tried response mode 2. I get different results but still not right... http://download.newstargames.com/misc/NSS4/CollisionProb4.avi http://download.newstargames.com/misc/NSS4/CollisionProb5.avi |
| ||
Si, I'm sure it's something to do with rotated meshes. Generally the collisions between the ball and stadium respond perfectly (even hitting the sloping stands and seating). If I do RotateEntity(stadium, 0, 20, 0) suddenly everything goes awry. |
| ||
Ah yes, the returned collision normals are wonky. To fix, comment out lines 187-195 in TCollision.bmx - these lines: TEntity.TFormPoint ent.collision[i].x#,ent.collision[i].y#,ent.collision[i].z#,ent2_hit,Null ent.collision[i].x#=TEntity.tformed_x ent.collision[i].y#=TEntity.tformed_y ent.collision[i].z#=TEntity.tformed_z TEntity.TFormNormal ent.collision[i].nx#,ent.collision[i].ny#,ent.collision[i].nz#,ent2_hit,Null ent.collision[i].nx#=TEntity.tformed_x ent.collision[i].ny#=TEntity.tformed_y ent.collision[i].nz#=TEntity.tformed_z |
| ||
Hi Si. That doesn't fix it I'm afraid. Take a look at this. Depending on the direction that the ball is moving, I get different results from the same collision entity. http://download.newstargames.com/misc/NSS4/CollisionProb6.avi |
| ||
Are you resetting nx/ny/nz before the loop ? |
| ||
Hmmm, not sure why your code might be failing. I've written a small program here that demonstrates some ball bouncing code that works OK - just run it from the minib3d examples folder: If you can reproduce the problem by writing a very small program with just the ball bouncing against an advertising hoarding, that would be a huge help. |
| ||
Ah man, I found it after a couple of hours of messing with your example. A bug in my code obviously. For some reason I was using a negative z velocity in TranslateEntity to apply curve to the ball flight. This was screwing things completely after a collision. I feel bad now for messing you about, sorry. |
| ||
It's OK - without this topic I wouldn't have known the normals bug existed! |