Collision Tutorial Object for T3D 1.2 help
by Bill Vee · in Torque 3D Professional · 09/03/2012 (1:34 pm) · 5 replies
First off I do understand that there are option available to get collision with a simple cube.
I am trying to provide collision to a custom class I created similar to the terrain and roadmesh objects.
I have tried for about 2 weeks now to get the Collision Tutorial Object to work with T3D 1.2.
Collision Tutorial Object
The download for this tutorial is broken so you can get it here
I have used the RenderMeshExample class as a starting point to add collision to it.
So far I can get it to register its convex and the player class will "find" it when looking for objects to collide against.
Here are some screenshots to show my progress.
The light blue object is a simple TSStatic of a cube used to stand on.
The screen shot was taken with the debug options player collision and render bounding boxes enabled.


As you can see the player is not colliding correctly with it.
The getPolyList function appears to be being called and returning the correct data back to the player class.
As the player crosses the point where the convex is the player is deflected slightly as if it hit something but continues on through the convex. Also if I jump on top of the box it will sometimes actually stop on top for a second then fall through it.
My first thought was that the convex planes were not set correctly but after setting and testing all possible configuration for each plane with no good results I am stumped.
The only results I got were the slight deflection or no deflection at all.
The castRay function appears to work fine as the camera and projectiles will collide against the object.
Not very useful as far as figuring out what is wrong as I believe the castRay will intersect a plane regardless of the direction the plane is "pointing".
I have went through the meshroad class and terrian class code to see what I may be doing wrong but so far I can't figure out why it isn't working right.
Anyone care to share some insight into the collision code I may not be aware of?
I am trying to provide collision to a custom class I created similar to the terrain and roadmesh objects.
I have tried for about 2 weeks now to get the Collision Tutorial Object to work with T3D 1.2.
Collision Tutorial Object
The download for this tutorial is broken so you can get it here
I have used the RenderMeshExample class as a starting point to add collision to it.
So far I can get it to register its convex and the player class will "find" it when looking for objects to collide against.
Here are some screenshots to show my progress.
The light blue object is a simple TSStatic of a cube used to stand on.
The screen shot was taken with the debug options player collision and render bounding boxes enabled.


As you can see the player is not colliding correctly with it.
The getPolyList function appears to be being called and returning the correct data back to the player class.
As the player crosses the point where the convex is the player is deflected slightly as if it hit something but continues on through the convex. Also if I jump on top of the box it will sometimes actually stop on top for a second then fall through it.
My first thought was that the convex planes were not set correctly but after setting and testing all possible configuration for each plane with no good results I am stumped.
The only results I got were the slight deflection or no deflection at all.
The castRay function appears to work fine as the camera and projectiles will collide against the object.
Not very useful as far as figuring out what is wrong as I believe the castRay will intersect a plane regardless of the direction the plane is "pointing".
I have went through the meshroad class and terrian class code to see what I may be doing wrong but so far I can't figure out why it isn't working right.
Anyone care to share some insight into the collision code I may not be aware of?
#2
To reiterate: I'm just guessing at the moment - I only did a quick scan of the code and have not actually tried to get it to work in a project. Hopefully that catches it, though.
09/03/2012 (9:35 pm)
Ok, I'm going to make a wild guess based on the single fact that this was for TGE - In the constructor (around line 405) the type masks are assigned. Be sure that these type masks are still in use in T3D; there was a large overhaul of type masks because there were many redundant and unused masks taking up space.To reiterate: I'm just guessing at the moment - I only did a quick scan of the code and have not actually tried to get it to work in a project. Hopefully that catches it, though.
#3
I am not using a physX right now.
@ - Richard Ranft
I did check the typemasks and adjusted the conversion accordingly.
As far as I can tell the built-in collision system in T3D is largely unchanged from TGE. Judging by the meshroad class and how it uses the collision system the TGE collision example is still pretty much valid.
I have made some progress.
In the getPolyList function I changed it to add the bounding box used for the object via the built-in addbox function for the AbstractPolyList class.
This caused the collision to work as expected. The object could be placed at any position and rotation and be collided against correctly.
Since I would rather build my own collision polys due to the fact that my collision convex is more complex than a simple box, I will need to know how to build a proper PolyList to return to the collision system.
I will have to debug step through the addbox function to see how it is correctly setting the vertex points and planes and in what order.
09/04/2012 (5:44 am)
@ - DreamPharaohI am not using a physX right now.
@ - Richard Ranft
I did check the typemasks and adjusted the conversion accordingly.
As far as I can tell the built-in collision system in T3D is largely unchanged from TGE. Judging by the meshroad class and how it uses the collision system the TGE collision example is still pretty much valid.
I have made some progress.
In the getPolyList function I changed it to add the bounding box used for the object via the built-in addbox function for the AbstractPolyList class.
This caused the collision to work as expected. The object could be placed at any position and rotation and be collided against correctly.
Since I would rather build my own collision polys due to the fact that my collision convex is more complex than a simple box, I will need to know how to build a proper PolyList to return to the collision system.
I will have to debug step through the addbox function to see how it is correctly setting the vertex points and planes and in what order.
#4
Here is a working renderMeshExample class with the collision code added.
It works when you use the renderMeshExample box to build the collision info via AbstractPolyList::addBox(bounding box).
I can't get the hand built method to create useable collision info and this is what I really need to know how to do.
I added some code to change if it uses the bound box to make the collision info or attempts to build the info by hand.
After you add the renderMeshExample to the mission, and change the material so you can see it, you can from the editor check UseBoxForCollision to alternate between the 2 methods.
If anyone can take a look and educate me as to what it is I am apparently doing wrong I would be very grateful.
09/04/2012 (6:01 pm)
OK , I have went up and down the collision code and I am at a lost as to what the problem is. Here is a working renderMeshExample class with the collision code added.
It works when you use the renderMeshExample box to build the collision info via AbstractPolyList::addBox(bounding box).
I can't get the hand built method to create useable collision info and this is what I really need to know how to do.
I added some code to change if it uses the bound box to make the collision info or attempts to build the info by hand.
After you add the renderMeshExample to the mission, and change the material so you can see it, you can from the editor check UseBoxForCollision to alternate between the 2 methods.
If anyone can take a look and educate me as to what it is I am apparently doing wrong I would be very grateful.
#5
Turns out it was a client server issue.
It was creating the geometry in prepRenderImage and since the server doesn't render it never created the info on the server side.
This explains the temporal effect I was seeing.
Here is the updated version of the renderMeshExample with collision.
If anyone wants to add this as a resource then by all means please do for the community.
09/05/2012 (6:10 am)
OK , I got it figured out.Turns out it was a client server issue.
It was creating the geometry in prepRenderImage and since the server doesn't render it never created the info on the server side.
This explains the temporal effect I was seeing.
Here is the updated version of the renderMeshExample with collision.
If anyone wants to add this as a resource then by all means please do for the community.
Torque Owner DreamPharaoh
Gods and Nemesis
In a physX build you can get the vehicle to collide with the player and initiate a mount if you take the vehicle in edit mode and slam it against the player, otherwise the player will walk right through it but the gun the player has selected will pull back when close to the vehicle. I do not fully understand the collision properties with physX, and no one has a solution for it yet.
The temporal collision could also be in result to a tick per second. In other words the computer checks for collision every so many milliseconds resulting in a failure when it is not checking for collision. This would be similar to when I was messing with a gravity gun. Its tick per millisecond will effect the smoothness of how an object behaves when being lifted. The faster the tick per second the smoother the movement. Otherwise I am at a loss on this one.