collisionWorld rayTest problem
-
- Posts: 9
- Joined: Thu Jan 10, 2008 3:53 am
collisionWorld rayTest problem
when rayTest's rayFromWorld is too close to object, it will failed hit on that object.
-
- Posts: 133
- Joined: Wed Jul 27, 2005 1:05 pm
- Location: Berkeley, CA
Re: collisionWorld rayTest problem
Is RayFromWorld within the margin expanded collision shape? That is not supported by the algorithm used.
-
- Posts: 66
- Joined: Fri Oct 12, 2007 6:28 pm
- Location: San Diego
Re: collisionWorld rayTest problem
I got around the problem of "hitting yourself" in rayTest by deriving my own ClosestRayResultCallback from bullet's, like this:
Then you use it like this:
You can pass NULL in and it's work fine (not ignoring anything).
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;
}
};
Code: Select all
MyClosestRayResultCallback rayCallback(from, to, pBulletCollisionObjectToIgnore);
pCollisionWorld->rayTest(from, to, rayCallback, nGroupFilter);
-
- Site Admin
- Posts: 4221
- Joined: Sun Jun 26, 2005 6:43 pm
- Location: California, USA
Re: collisionWorld rayTest problem
Can you describe 'failed hit? Do you mean that there is no hit reported at close proximity?showcat wrote: when rayTest's rayFromWorld is too close to object, it will failed hit on that object.
If that is the case, we need to check and fix that bug.
Thanks for the report,
Erwin
-
- Posts: 9
- Joined: Thu Jan 10, 2008 3:53 am
Re: collisionWorld rayTest problem
First, sorry for my poor English skill.
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:
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.
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 can post some picture later.
-
- Site Admin
- Posts: 4221
- Joined: Sun Jun 26, 2005 6:43 pm
- Location: California, USA
Re: collisionWorld rayTest problem
We'll add some testcase, and make sure the raytest gives a hit when touching and/or inside a convex shape.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.
Thanks for the feedback,
Erwin
-
- Posts: 9
- Joined: Thu Jan 10, 2008 3:53 am
Re: collisionWorld rayTest problem
normal condition
cross the wall
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.
cross the wall
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.