HexDump
20-01-2008 23:20:34
Hi all,
I´m trying to do a simple raycast, and I´m not getting good resulsts. This is the Raycast code:
CPhysicsComp* pPhysic=this->m_pOwner->GetComponent<CPhysicsComp>();
CGameEntity* p=this->m_pOwner;
Vector3 p1=p->GetPosition()+Vector3(0,-1.0f,0);
OgreNewt::BasicRaycast raycast(CPhysicsSystem::getSingletonPtr()->GetPhysicsWorld(),p->GetPosition(),p1);
if(raycast.getHitCount()>0)
{
OgreNewt::BasicRaycast::BasicRaycastInfo info=raycast.getFirstHit();
float fDist=-1.0f*info.mDistance;
if(fDist<=1.0f)
m_bIsOnFloor=true;
}
As you can see I´m just firing a ray downwards.
The problem is that the raycast is hitting my world but I´m not getting any hitcount. I´m sure it is hitting it because I have some debug lines for the raycast and it is hitting ground.
Do anybody know what could be happening? anyother with same prob?
Thanks in advance,
HexDump.
dudeabot
21-01-2008 01:19:11
Hi all,
I´m trying to do a simple raycast, and I´m not getting good resulsts. This is the Raycast code:
CPhysicsComp* pPhysic=this->m_pOwner->GetComponent<CPhysicsComp>();
CGameEntity* p=this->m_pOwner;
Vector3 p1=p->GetPosition()+Vector3(0,-1.0f,0);
OgreNewt::BasicRaycast raycast(CPhysicsSystem::getSingletonPtr()->GetPhysicsWorld(),p->GetPosition(),p1);
if(raycast.getHitCount()>0)
{
OgreNewt::BasicRaycast::BasicRaycastInfo info=raycast.getFirstHit();
float fDist=-1.0f*info.mDistance;
if(fDist<=1.0f)
m_bIsOnFloor=true;
}
As you can see I´m just firing a ray downwards.
The problem is that the raycast is hitting my world but I´m not getting any hitcount. I´m sure it is hitting it because I have some debug lines for the raycast and it is hitting ground.
Do anybody know what could be happening? anyother with same prob?
Thanks in advance,
HexDump.
hello, try
Vector3 p1=Vector3::NEGATIVE_UNIT_Y * 200; //200 units downside
HexDump
21-01-2008 08:19:00
Why should I try 200? 200 is too much for me, because I want to snap to the ground and in my world 200 units is a lot. 1 unit is enough as I see in my debug representation. Thanks for trying to help mate, but this is not a solution. Anyone else?
Thanks in advance,
HexDump.
nullsquared
21-01-2008 20:09:35
Try waking up the ground first (the unfreeze function didn't always work for me, apply a small impulse to wake it up). I've noticed that my ray casts sometimes fail when objects they intersect are at rest.
HexDump
21-01-2008 23:23:34
Well, it is pretty strange, this is my apply force callback:
Vector3 TargetVel=m_pOwner->GetVelocity();
Vector3 CurVel=m_pBody->getVelocity();
float fDeltaVel=TargetVel.x-CurVel.x;
float fForce=fDeltaVel*50*m_fMass;
Vector3 GravityForce=Vector3(0,-10.0f,0)*m_fMass;
m_pBody->addForce(Vector3(fForce,CurVel.y,CurVel.z)+GravityForce);
As you can see, I apply a gravity and a displacement along the x asis. It is trange that if I let my body just fall the raycast is not working properly but If I move the body left o right it does... Pretty strange :S.
Thanks in advance,
HexDump.
dudeabot
22-01-2008 00:56:22
if its your controlling character you might consider using
setAutoFreeze(0) on the body, on its creation
weird - i dont have issues raycasting rest bodies
HexDump
22-01-2008 08:12:58
I have used autoFreeze(0), unfreeze() after that, etc... And it doesn´t matter I have to do allways the same. Anyway if you have a look at the code you can see that I do an addForce of Gravity+The X axis force. I think it is not a freezing usue because both forces are added same way, but Raycast only works when there exists a X axis force, odd, odd.
Thanks in advance,
HexDump.
Hansel
22-01-2008 12:09:10
I have similar problems with basic raycasting with the latest Ogre versions. I use raycasting to positionate trees and other objects over a terrain and rayscast fails to detect the terrain the 98% of the times.
Months ago the same code works perfectly so I think it's a "incompatibility" with Ogre 1.4.5-1.4.6. I have to probe it.
HexDump
22-01-2008 14:42:30
I will move to 1.4.2 tonight, and check if this is the problem. Anyway, the thing that moving along X axes does the raycast work tells me it is not a ogrenewt <->ogre 1.4.6 issue.
HexDump.
HexDump
22-01-2008 18:18:38
Well, it was my fault ¬¬. My code did something that prevented the raycast to collide... shame on me

.
Thanks in advance,
HexDump.