Physics Simulation Forum

 

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Mon Jul 03, 2017 9:03 pm 
Offline

Joined: Sat May 27, 2017 8:16 am
Posts: 9
I am using just a box rigidbody to fake the whole locomotion. It is very basic and I am not raycasting for the wheels.

The faked locomotion is good enough for my purpose.

My problem is not to drive it while it is not on the ground.

If I just raycast from the center, it does not work on the ramps (which makes perfect sense as the right and left edge will be touching to the ground where as the center is in the air).

So, I was thinking about raycasting 4 lines from 4 bottom corners of the rigidbody in the -Y axis direction + center. So if at least 1 of them hits, that means it is grounded.

On the other hand, I am also thinking about using convexTest?

Which one would be better for the performance? Just shape casting looks like the perfect solution but I would be glad if you share your experience with me.


Top
 Profile  
 
PostPosted: Thu Jul 06, 2017 4:55 pm 
Offline
User avatar

Joined: Tue Sep 30, 2014 6:03 pm
Posts: 306
Location: San Francisco
Would you want to disable driving the box when it is actually touching the ground, or do you want to disable it when it is above the ground almost touching?

If you want to rely on contacts with the ground you can harvest the contact manifolds every frame and look for one between the box and something below it. Here is code that might work (dunno if this even compiles):
Code:
// given:  collisionDispatcher, boxBody, and worldUp

int numManifolds = collisionDispatcher->getNumManifolds();
for (int i = 0; i < numManifolds; ++i) {
    btPersistentManifold* contactManifold =  collisionDispatcher->getManifoldByIndexInternal(i);
    if (contactManifold->getNumContacts() > 0) {
        const btCollisionObject* objectA = static_cast<const btCollisionObject*>(contactManifold->getBody0());
        const btCollisionObject* objectB = static_cast<const btCollisionObject*>(contactManifold->getBody1());

        // Note: the order of the objects A and B is arbitrary, but the contactPoint's normal
        // always points from objectB toward objectA, so we figure out which one is boxBody and
        // reverse the direction if the normal when boxBody is objectB.
        btRigidBody* otherBody = nullptr;
        btScalar sign = 1.0f;
        if (objectA == boxBody) {
            otherBody == static_cast<btRigidBody*>(objectB);
        } else if (objectB == boxBody) {
            otherBody == static_cast<btRigidBody*>(objectA);
            sign = -1.0f;
        }

        if (otherBody) {
            btVector3 normal = sign * contactManifold->getContactPoint(0).m_normalWorldOnB;
            const btScalar UPWARD_NORMAL_THRESHOLD = 0.0f;  // maybe should be non-zero?
            if (normal.dot(worldUp) > UPWARD_NORMAL_THRESHOLD) {
                // boxBody is probably bumping into something below it
                // TODO: figure out what to do:
                //   break here?
                //   continue to analyze the rest of the manifold (which can have up to four points)?
                //   continue to look for more manifolds with other objects below bodyBox?
            }   
        }   
    }   
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: Bing [Bot] and 16 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group