collisions with moving objects

BlitzMax Forums/MiniB3D Module/collisions with moving objects

bradford6(Posted 2007) [#1]
I am embarking on a fun-filled journey into 3D Mathematics with the hope of coming up with a wonderful demo for all to enjoy and learn from.

Using MiniB3D's built in collision system I am trying to come up with a reusable, easy to understand system of applying collision responses to moving objects.

I realize that Klepto2 is working on a Newton Dynamics Module (very excited about that!) but I think it will be useful to understand thge miniB3D/Blitz3D collision system a little better.


scenario:
I have a mesh called "Level" and a sphere called "Player"

I have collisions set
Const PLAYER_TYPE = 1
Const LEVEL_TYPE = 2
Const MOVING_TYPE = 3
Const SPHERE2MESH = 4
Const ELLIPSE2MESH = 2
Const RESPONSE_FULL_SLIDE = 2

Collisions PLAYER_TYPE,LEVEL_TYPE , ELLIPSE2MESH , RESPONSE_FULL_SLIDE	


this works very well. the player slides around the mesh (I have a small bit of gravity pulling him (-Y) direction.

I also have moving platforms that are of collision type 'LEVEL_TYPE'. These platforms simply move up and down on a timer (+y and -y)

PROBLEM: when the player is on top of the +Y moving platform, he falls through. after perusing Simonh's collision code, It confirmed that Collision detection is hard. The cool thing is that I can get the Collision Normals (CollisionNX,NY,NZ) and all of the other collision info each frame. It is just trying to figure out the best way to use it that has me stumped. Also, MiniB3D has a very nice TVector class that may come in handy.




I am working on a solution to the 2 moving 3D entities problem

possible solutions:
1. get the Velocity Vector of the Platform (old position - new position) and apply that exact amount to the Player Entity.

2. Parent the entity to the platform when it collides. then all movement will be in the 'parent space' (i.e the local coordinate system of the platform) until the player either jumps off or moves to the edge and falls off. then I would 'unparent' the player from the platform. (and maybe 'parent' the player to the 'Level' mesh?)

3. convert all movements to a 3D vector and add the player vector to the platform vector. (Velocity vector)

4. Use a line pick from the bottom of the player down. if it hits a platformadjust the position of the player to match the pick position.

now, finally my question:

what method would you use?

I could create a function that would parent/unparent based on collisions that would not occur every frame. i.e would have a bit of 'parent memory' so I would not have to call EntityParent too much.

it seems tha advantage of parenting is that if a platform is rotating, the rotation axis would be that of the parent and the player would maintain the correct position and rotation.

I do not have any (good) code to post, hopefully a demo real soon...


simonh(Posted 2007) [#2]
You could try using this code. I'll probably incorporate it into MiniB3D at some point.

It works simply by pretending that the destination entity is moving but in fact moving the source entity in the opposite direction to the destionation entity.


bradford6(Posted 2007) [#3]
ha ha. some user by the name of simonh posted that 3 years ago.

I *just* got done converting this over to blitzmax when you posted. fits the bill nicely. I changed the playermesh to a cube to visualize the rotations.

very nice code by the way.