Should I screw with Container::castRay?
by Joshua "The Power Nap" Taylor · in Torque Game Engine · 05/31/2002 (11:28 am) · 2 replies
Howdy,
I've been working on hand to hand weapons, and I'd like to have them collide with the enviroment around them(walls, ground, etc).
So I looked at the collision code in the Projectile::processTick function and came up with using getContainer()->castRay.
The problem with this is that it allways returns the player, because the player is holding it.
So I looked at Container::castRay and I figured that if I added a parameter to the function call
from
Container::castRay(const Point3F &start, const Point3F &end, U32 mask, RayInfo* info)
to
Container::castRay(const Point3F &start, const Point3F &end, U32 mask, RayInfo* info,SceneObject* ObjectToIgnore)
and added the code on line 1166 in sceneobject.cc
from
RayInfo ri;
if (ptr->castRay(xformedStart, xformedEnd, &ri)) {
if(ri.t < currentT) {
*info = ri;
info->point.interpolate(start, end, info->t);
currentT = ri.t;
}
to
RayInfo ri;
if (ptr->castRay(xformedStart, xformedEnd, &ri)) {
if(ri.t < currentT && ri.object != ObjectToIgnore) {
*info = ri;
info->point.interpolate(start, end, info->t);
currentT = ri.t;
}
That is shouldn't return the ObjectToIgnore, or in my case the player. Would that work?(I know on line 1237 there is the exact same logic block, and of course that would be changed to) That, and instead of adding basically redundant fucntions turn the original into
Container::castRay(const Point3F &start, const Point3F &end, U32 mask, RayInfo* info)
{
castRay(start,end,mask,info,NULL);
};
The reason I'm asking is that I only have a rough idea of how castRay works, and I don't want to break anything.
Thanx in advance
Josh
I've been working on hand to hand weapons, and I'd like to have them collide with the enviroment around them(walls, ground, etc).
So I looked at the collision code in the Projectile::processTick function and came up with using getContainer()->castRay.
The problem with this is that it allways returns the player, because the player is holding it.
So I looked at Container::castRay and I figured that if I added a parameter to the function call
from
Container::castRay(const Point3F &start, const Point3F &end, U32 mask, RayInfo* info)
to
Container::castRay(const Point3F &start, const Point3F &end, U32 mask, RayInfo* info,SceneObject* ObjectToIgnore)
and added the code on line 1166 in sceneobject.cc
from
RayInfo ri;
if (ptr->castRay(xformedStart, xformedEnd, &ri)) {
if(ri.t < currentT) {
*info = ri;
info->point.interpolate(start, end, info->t);
currentT = ri.t;
}
to
RayInfo ri;
if (ptr->castRay(xformedStart, xformedEnd, &ri)) {
if(ri.t < currentT && ri.object != ObjectToIgnore) {
*info = ri;
info->point.interpolate(start, end, info->t);
currentT = ri.t;
}
That is shouldn't return the ObjectToIgnore, or in my case the player. Would that work?(I know on line 1237 there is the exact same logic block, and of course that would be changed to) That, and instead of adding basically redundant fucntions turn the original into
Container::castRay(const Point3F &start, const Point3F &end, U32 mask, RayInfo* info)
{
castRay(start,end,mask,info,NULL);
};
The reason I'm asking is that I only have a rough idea of how castRay works, and I don't want to break anything.
Thanx in advance
Josh
#2
Now that I think about it, the projectile code makes more sence.
Josh
06/01/2002 (11:44 am)
Sweet,Now that I think about it, the projectile code makes more sence.
Josh
Associate Mark Frohnmayer
The functionality you are looking for is already in there via the disableCollision() function - just do
playerObject->disableCollision();
getContainer()->castRay(...);
playerObject->enableCollision();