CastRay collision question
by Dumbledore · in Torque Game Engine · 05/31/2008 (10:53 am) · 4 replies
Hello,
I was under the impression that projectile collision works thusly:
1. Projectile casts a ray from its old position to its new position
2. The server/client iterate through all the objects in the bins the ray intersects calling castRay() on each of them.
3. castRay() takes the start and end point of the ray and determines if the ray intersects it
4. If it does, it returns true
5. If the castRay returns true then check RayInfo to get more information on the object it collided with.
The problem I have is twofold. One: why does increasing the ray ahead farther not make the collision occur "sooner".
My results with the above attempt seem to have no difference than if i just made it
Two: when the Projectile collides with a RTSUnit derived from Player, it detects the collision and returns true, but for some reason, it doesn't explode. I should clarify a little. The call to RTSUnit::castRay() will return true because it collides, but then Container::castRay() returns false. Why?
I can't understand the code in Container::castRay() to answer this myself. For one thing, what does ri.t and currentT stand for?
I was under the impression that projectile collision works thusly:
1. Projectile casts a ray from its old position to its new position
2. The server/client iterate through all the objects in the bins the ray intersects calling castRay() on each of them.
3. castRay() takes the start and end point of the ray and determines if the ray intersects it
4. If it does, it returns true
5. If the castRay returns true then check RayInfo to get more information on the object it collided with.
The problem I have is twofold. One: why does increasing the ray ahead farther not make the collision occur "sooner".
newPosition = oldPosition + mCurrVelocity * (F32(TickMs) / 1000.0f)
Point3F fartherAhead = newPosition;
fartherAhead.normalize();
fartherAhead * = 5; Make it 5 units in the same direction as oldPosition - newPosition
fartherAhead = newPosition + fartherAhead;
if ( Container::castRay(oldPosition, fartherAhead, mask, &rInfo) == true )
{
// we collided with something.
}My results with the above attempt seem to have no difference than if i just made it
if ( Container::castRay(oldPosition, newPosition, mask, &rInfo) == true )
{
// we collided with something.
}Two: when the Projectile collides with a RTSUnit derived from Player, it detects the collision and returns true, but for some reason, it doesn't explode. I should clarify a little. The call to RTSUnit::castRay() will return true because it collides, but then Container::castRay() returns false. Why?
I can't understand the code in Container::castRay() to answer this myself. For one thing, what does ri.t and currentT stand for?
#2
05/31/2008 (11:28 am)
Will "fartherAhead * = 5;" work just like "fartherAhead *= 5;"? Could that be it?
#3
thanks anyway
05/31/2008 (11:33 am)
Hi Morrock, it seems to just be showing up that way in the code block for the forum. It is "fartherAhead *= 5;"thanks anyway
#4
05/31/2008 (12:10 pm)
Oh i figured it out. My math was wrong. Shoulda beennewPosition = oldPosition + mCurrVelocity * (F32(TickMs) / 1000.0f)
Point3F fartherAhead = newPosition - oldPosition;
fartherAhead.normalize();
fartherAhead * = 5; Make it 5 units in the same direction as oldPosition - newPosition
fartherAhead = newPosition + fartherAhead;
if ( Container::castRay(oldPosition, fartherAhead, mask, &rInfo) == true )
{
// we collided with something.
}
Torque Owner Dumbledore
Any hints for number 1 though?