collisionWorld rayTest problem

Post Reply
snowcat
Posts: 9
Joined: Thu Jan 10, 2008 3:53 am

collisionWorld rayTest problem

Post by snowcat »

when rayTest's rayFromWorld is too close to object, it will failed hit on that object.
User avatar
John McCutchan
Posts: 133
Joined: Wed Jul 27, 2005 1:05 pm
Location: Berkeley, CA
Contact:

Re: collisionWorld rayTest problem

Post by John McCutchan »

Is RayFromWorld within the margin expanded collision shape? That is not supported by the algorithm used.
reltham
Posts: 66
Joined: Fri Oct 12, 2007 6:28 pm
Location: San Diego

Re: collisionWorld rayTest problem

Post by reltham »

I got around the problem of "hitting yourself" in rayTest by deriving my own ClosestRayResultCallback from bullet's, like this:

Code: Select all

struct	MyClosestRayResultCallback : public btCollisionWorld::ClosestRayResultCallback
{
    MyClosestRayResultCallback(const btVector3& rayFromWorld, const btVector3& rayToWorld, btCollisionObject* pObjectToIgnore)
        : btCollisionWorld::ClosestRayResultCallback(rayFromWorld, rayToWorld), m_collisionObjectToIgnore(pObjectToIgnore)
    {
    }

    btCollisionObject* m_collisionObjectToIgnore;

    virtual btScalar AddSingleResult(btCollisionWorld::LocalRayResult& rayResult, bool normalInWorldSpace)
    {
        if (rayResult.m_collisionObject != m_collisionObjectToIgnore)
        {
            return btCollisionWorld::ClosestRayResultCallback::AddSingleResult(rayResult, normalInWorldSpace);
        }
        return rayResult.m_hitFraction;
    }
};
Then you use it like this:

Code: Select all

    MyClosestRayResultCallback rayCallback(from, to, pBulletCollisionObjectToIgnore);
    pCollisionWorld->rayTest(from, to, rayCallback, nGroupFilter);
You can pass NULL in and it's work fine (not ignoring anything).
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: collisionWorld rayTest problem

Post by Erwin Coumans »

showcat wrote: when rayTest's rayFromWorld is too close to object, it will failed hit on that object.
Can you describe 'failed hit? Do you mean that there is no hit reported at close proximity?

If that is the case, we need to check and fix that bug.
Thanks for the report,
Erwin
snowcat
Posts: 9
Joined: Thu Jan 10, 2008 3:53 am

Re: collisionWorld rayTest problem

Post by snowcat »

First, sorry for my poor English skill. :oops:

I'm woking on a project - third person shooting game. In the test scene, player is in a room. The wall of this room is using btConvexHullShape(because I didn't finish property based shape code, so I use btConvexHullShape for all objects of the scene).
When player shoot walls, sometime the rayTest failed. Bullet which player fired is calculated every frame like this:

Code: Select all

Vector3 direction = m_node->getOrientation() * Vector3::UNIT_Z;
Real len = time_since_last_frame * m_speed;
Vector3 move = direction * len;

// Hit Test
Vector3 cur_pos = m_node->getPosition();
Vector3 tar_pos = cur_pos + move;
btVector3 ray_from( btVector3( cur_pos.x, cur_pos.y, cur_pos.z ) );
btVector3 ray_to( btVector3( tar_pos.x, tar_pos.y, tar_pos.z ) );
btCollisionWorld::ClosestRayResultCallback closest_result( ray_from, ray_to );
m_world->rayTest( ray_from, ray_to, closest_result );

if( closest_result.HasHit() )
{
    // fire some particles
}
else
{
    // move bullet mesh forward
}
I made some code for test this, using a same time step(use same time_since_last_frame to draw and calculate everything). I can see when bullet is very close to walls, next frame it will cross wall without hit.
I can post some picture later.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: collisionWorld rayTest problem

Post by Erwin Coumans »

snowcat wrote:I made some code for test this, using a same time step(use same time_since_last_frame to draw and calculate everything). I can see when bullet is very close to walls, next frame it will cross wall without hit.
I can post some picture later.
We'll add some testcase, and make sure the raytest gives a hit when touching and/or inside a convex shape.

Thanks for the feedback,
Erwin
snowcat
Posts: 9
Joined: Thu Jan 10, 2008 3:53 am

Re: collisionWorld rayTest problem

Post by snowcat »

normal condition
Image
cross the wall
Image
all bullets at same speed, with same frame time, so distance between two bullets are same.
And the rayTest is same from bullet to bullet.
The real position of bullet is at bullet center, not bullet head.
Post Reply