Sign in to follow this  
Ravuya

Tokamak neSensor doesn't seem to work.

Recommended Posts

I've chosen to try out Tokamak for a racing game, and so I've looked at the example code, which uses neSensor (presumably a raycast sensor) and tried to implement it on my own. However, the neSensor never seems to actually detect a collision with other rigid bodies (or even its housing body); I've put another rigid body (with collision geometry) under it and it doesn't seem to ever have a collision depth that's not 0. If I put an neAnimatedBody (which is a rigid body that doesn't move) under it, I get a contact with what seems like the correct distance and collided body, but only immediately after the rigid body's geometry has collided with that of the animated body, which defeats the purpose. It seems like I've missed some state because the sensor only "wakes up" immediately after a collision. I have no idea why the sensor doesn't work, and I've tried a few things like turning off the object which owns the sensor's collision geometry. The straight geometry collision works fine, but not sensors. Here's a code snippet, if it helps:
// Bring up the physics core
neV3 gravity = {0, -0.32f, 0};
PhysicsManager physicsWorld(gravity);
// Create a physics body
neRigidBody* target = physicsWorld.AddRigidBody("target"); // calls neSimulator::CreateRigidBody
neV3 targetInitialPosition = {0.0f, -2.0f, -4.0f};
target->SetPos(targetInitialPosition);
target->SetMass(0.6f);
	
GameRigidBody targetWatcher(target);						// wraps it to display some debugging info on screen (boxes)
target->GravityEnable(false);

neRigidBody* dropped = physicsWorld.AddRigidBody("dropped");
targetInitialPosition.Set(0.0f, 2.0f, -4.0f);
dropped->SetPos(targetInitialPosition);
dropped->SetMass(1.6f);

GameRigidBody droppedWatcher(dropped);
dropped->GravityEnable(true);
neGeometry * geom1 = target->AddGeometry();
neGeometry * geom2 = dropped->AddGeometry();

neV3 boxSize;
boxSize.Set(1.0f, 1.0f, 1.0f);
geom1->SetBoxSize(boxSize);
geom2->SetBoxSize(boxSize);

neSensor* sn;
sn = dropped->AddSensor();
neV3 snPos, snDir;
snDir.Set(0.0f, -1.0f, 0.0f); // basically, pointing straight down. If I change this to +/- 9000000, it still doesn't work, so it's not a 'length' issue that I can see.
snPos.Set(0.0f, 0.0f, 0.0f);
sn->SetLineSensor(snPos, snDir);

// Remember to invoke these after changing collision geometry. Also updates sensors.
dropped->UpdateBoundingInfo();
target->UpdateBoundingInfo();


Tokamak seems like it's fine for my needs, but I just have to get over the initial hump (and lack of current documentation). What I've entered there is more or less the same as what they have in the Tokamak car sample. I'm not sure if the length of my sensors should be shorter or longer or what. I'm using a delta timestep, but even with a fixed timestep (1/60.0f) it exhibits the same behavior. It seems the simulation engine is skipping over the sensors altogether even though the neSimulatorSizeInfo says that one sensor is present. Edit: When I impact, the sensor seems to be "off" at an angle; is there something weird here with parallel objects? Do I need to add another box that doesn't respond to collisions in order to do a broad-phase "sweep" before the sensor tries it? If so, that's a pretty egregious miss in the documentation and the example. [Edited by - Ravuya on January 19, 2009 10:47:10 PM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this