Jump to content
  • Advertisement
Sign in to follow this  

Tokamak neSensor doesn't seem to work.

This topic is 3619 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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};
GameRigidBody targetWatcher(target);						// wraps it to display some debugging info on screen (boxes)

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

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

neV3 boxSize;
boxSize.Set(1.0f, 1.0f, 1.0f);

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.

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
Okay, problem solved: it turns out in Tokamak the sensor value is only valid during the RigidBodyControllerCallback. Outside of the callback, the values cannot be accessed properly from the game loop.

Thanks, guys!

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!