Vehicle Collisions
by Adam · in Torque Game Engine · 02/15/2002 (1:15 pm) · 12 replies
Greetings All,
I'm currently working on a modified Hover Vehicle class in an attempt to make some boats. Right now I have them behaving properly in every way (minus transforming in accordance with waves but that's not the concern at the moment). Right now I'm having trouble with boats and land collision. Since they are based on hover vehicles I basically have their stabLenMin and stabLenMax values set appropriately so that they ride low enough in the water, what I want to do however is prevent them from going on land or currently engaging in the nasty land collisions that are proving to be quite the problem. Right now my means of preventing them from going on land (which works with decent if not terribly great results) is messing with the void HoverVehicle::updateForces(F32 /*dt*/) function. Right now I've been messing with this block:
if (getContainer()->castRay(stabPoints[j].wsPoint, stabPoints[j].wsPoint + stabPoints[j].wsExtension * 2.0,
TerrainObjectType | InteriorObjectType | WaterObjectType, &rinfo)) {
reallyFloating = false;
if (rinfo.t <= 0.5) {
// Ok, stab is in contact with the ground, let's calc the forces...
compression[j] = (1.0 - (rinfo.t * 2.0)) * baseStabLen;
}
normalSet[j] = true;
normalMod[j] = rinfo.t < 0.5 ? 1.0 : (1.0 - ((rinfo.t - 0.5) * 2.0));
normal[j] = rinfo.normal;
}
I've tried a mix of things, from setting the mainThrustForce to 0 if the if(rinfo.t <= 0.5) statement is true to changing the getContainer()->castRay() call to only WaterObjectType. I'm wondering if I'm on the right track here as my boat is still not resolving collisions well and tends to get stuck in the terrain (as opposed to going up it, which is a semi good thing). Basically what I'm looking for is a means of testing a small radius around the boat for land and denying movement in that direction.
Any suggestions, code snippets etc. Are greatly appreciated.
I'm currently working on a modified Hover Vehicle class in an attempt to make some boats. Right now I have them behaving properly in every way (minus transforming in accordance with waves but that's not the concern at the moment). Right now I'm having trouble with boats and land collision. Since they are based on hover vehicles I basically have their stabLenMin and stabLenMax values set appropriately so that they ride low enough in the water, what I want to do however is prevent them from going on land or currently engaging in the nasty land collisions that are proving to be quite the problem. Right now my means of preventing them from going on land (which works with decent if not terribly great results) is messing with the void HoverVehicle::updateForces(F32 /*dt*/) function. Right now I've been messing with this block:
if (getContainer()->castRay(stabPoints[j].wsPoint, stabPoints[j].wsPoint + stabPoints[j].wsExtension * 2.0,
TerrainObjectType | InteriorObjectType | WaterObjectType, &rinfo)) {
reallyFloating = false;
if (rinfo.t <= 0.5) {
// Ok, stab is in contact with the ground, let's calc the forces...
compression[j] = (1.0 - (rinfo.t * 2.0)) * baseStabLen;
}
normalSet[j] = true;
normalMod[j] = rinfo.t < 0.5 ? 1.0 : (1.0 - ((rinfo.t - 0.5) * 2.0));
normal[j] = rinfo.normal;
}
I've tried a mix of things, from setting the mainThrustForce to 0 if the if(rinfo.t <= 0.5) statement is true to changing the getContainer()->castRay() call to only WaterObjectType. I'm wondering if I'm on the right track here as my boat is still not resolving collisions well and tends to get stuck in the terrain (as opposed to going up it, which is a semi good thing). Basically what I'm looking for is a means of testing a small radius around the boat for land and denying movement in that direction.
Any suggestions, code snippets etc. Are greatly appreciated.
About the author
#2
02/15/2002 (7:01 pm)
I don't know the exact version number but it is the head from at least 3 or 4 weeks ago. I'll grab the newest head on Sunday when I get home (I'm attached to this site even when I'm not home :) ) and back to my work machine. I'll let you know how it works out, also thanks for the help Tim.
#3
Unfortunately it had the same effect. So I'm wondering is this something with the new vehicle modifications or did I just make a really stupid mistake somewhere (I'm hoping this is the case). I'm just wondering if anyone else has had any similar problems with hover vehicles with the new vehicle revisions. Any suggestions/assistance is as always greatly appreciated.
-Adam
02/17/2002 (7:46 pm)
Ok, I downloaded the head tonight and compiled it with my added floating vehicle class. Upon placing my boat in the world it started to just sink, regardless of the height at which it was placed it would just sink until it collided with something and it would then just continue to attempt to resolve the collision. Thinking this may have been just my model, I tried a few others to the same effect, I then decided to try it with Hover Vehicle, same effect, and then as my last attempt I loaded up the Tribes 2 WildCat, model, script and all. Unfortunately it had the same effect. So I'm wondering is this something with the new vehicle modifications or did I just make a really stupid mistake somewhere (I'm hoping this is the case). I'm just wondering if anyone else has had any similar problems with hover vehicles with the new vehicle revisions. Any suggestions/assistance is as always greatly appreciated.
-Adam
#4
in game/vehicle.cc, search for Vehicle::onNewDataBlock() function and comment out the lines:
mRigid.mass = mDataBlock->mass;
and
mRigid.setObjectInertia();
Let me know if that works.
02/18/2002 (8:40 am)
Well, I tried not to make any changes that would effect the basic behavior of other vehicle class, but it's entirely possible that I did... oh... I just though of something, I think I know what it is. Try this...in game/vehicle.cc, search for Vehicle::onNewDataBlock() function and comment out the lines:
mRigid.mass = mDataBlock->mass;
and
mRigid.setObjectInertia();
Let me know if that works.
#5
F32 Kg = 0.5 * mRigid.mass * G * G;
to
F32 Kg = 0.5 * mRigid.mass * G;
and my vehicles are now flying properly again, although they still seem to hit the ground when they are not mounted the first time and then stabilse out.
02/18/2002 (9:16 am)
I was working on some flying vehicles and updated to the head release. When trying to fly with the vehicle it would go almost snail like pace. I tried the above changes and it made the vehicle go light speed and crash the engine. I then changed the line in void Vehicle::updatePos.F32 Kg = 0.5 * mRigid.mass * G * G;
to
F32 Kg = 0.5 * mRigid.mass * G;
and my vehicles are now flying properly again, although they still seem to hit the ground when they are not mounted the first time and then stabilse out.
#6
-Adam
02/18/2002 (10:55 am)
Tim, it works perfectly, I'm going to tweak my class some more to see if I can prevent it from going on land but this helps quite a bit, thank you very very much.-Adam
#7
-Adam
(Images Below)
The ship is completely stuck in the terrain at this point, even though the collision geometry covers this area.
Image 1
Here is another angle of the shot above.
Image 2
Here is a picture of the collision geometry, the collision mesh is the gray planes around the ship.
Image 3
02/20/2002 (12:59 pm)
After testing with the head I've found a few odd things, in my messing around with the floating vehicle class I've managed to make it so that I can succesfully collide head on with land and not actually move up it, or move up it just a bit and then slide back down by messing with the updateForces function. The only real problem is side collisions, were I to side swipe some terrain, bad things happen, being more specific bad things includes clamping onto the terrain or getting stuck in it with collision not resolving. Included are some pictures, the first two are of one such sticking occasion, the third is the actual collision mesh on my vehicle just in case that might be posing a problem. Also, we've tried making the collision geometry a cube just in case the irregular geometry wasn't agreeing with the engine. Any assistance or reccomendations are as always greatly appreciated, specifically as to my approach to prevent ships from moving onto land, I'm not sure if my updateForces approach is neccesarily the best.-Adam
(Images Below)
The ship is completely stuck in the terrain at this point, even though the collision geometry covers this area.
Image 1
Here is another angle of the shot above.
Image 2
Here is a picture of the collision geometry, the collision mesh is the gray planes around the ship.
Image 3
#8
What vehicle class are you using again? and what changes have you made? I'd like to test on this side a little, but without your changes it would be difficult :)
02/21/2002 (9:23 am)
Looks pretty cool :) I definitely need to take another look at the collision code... There are a few things I need to take care of, but next week I may be able to take another pass at it.What vehicle class are you using again? and what changes have you made? I'd like to test on this side a little, but without your changes it would be difficult :)
#9
I emailed you a zip full of goodies that should allow you to reproduce the problem, included in it is a description of all of the files included. Thanks for taking the time to look at this for me.
-Adam
02/22/2002 (9:59 am)
Hey Tim,I emailed you a zip full of goodies that should allow you to reproduce the problem, included in it is a description of all of the files included. Thanks for taking the time to look at this for me.
-Adam
#10
02/23/2002 (9:40 am)
Tim, I tried your fix, which did somewhat help, but now the wheeled vechile racing mod goes nutty. Also, with the flyer I am now getting stuck in the ground on collision.
#11
02/23/2002 (9:57 am)
The code really should stay the way it is. The "fix" I mentioned was more just to see if that's what was causing problems. To correctly "fix" your vehicles, you should leave the code alone and simply increase the forces on the fling and hover vehicles. Basically what's going on is that the old code did not include the vehicle mass in any of the physics caclulations, I fixed that so the wheeled vehicles would have mass, but that throws off all the flying and hover vehicle forces. That make sense :)
Torque Owner Tim Gift
I'll probably continue to work on this a little, hopefully you should just be able to let the hull of your ship collide normally.