Check object in raycast problems - SOLVED

Expanding and utilizing the engine via C++.
1 post Page 1 of 1
Steve_Yorkshire
Posts: 247
Joined: Tue Feb 03, 2015 10:30 pm
 
  by Steve_Yorkshire » Fri Jun 23, 2017 5:15 pm
I'm having trouble getting a function to identify the object it hits. I want it to return true if it's target is hit and only it's target. When I hide behind other players/AI it returns true even though the view should be blocked by said other player objects.

I had started off with a simple
if (rInfo.object == target)
			return true;
But that didn't block the raycast with other players.

Full code for the function below:
bool AIPlayer::checkClearLos(GameBase* target, bool _checkEnabled)
{
	if (!isServerObject()) return false;
	if (!target)
	{
		target = mAimObject.getPointer();
		if (!target)
			return false;
	}
	if (_checkEnabled)
	{
		if (target->getTypeMask() & ShapeBaseObjectType)
		{
			ShapeBase *shapeBaseCheck = static_cast<ShapeBase *>(target);
			if (shapeBaseCheck)
				if (shapeBaseCheck->getDamageState() != Enabled) return false;
		}
		else
			return false;
	}

	RayInfo rInfo;

	disableCollision();

	S32 mountCount = target->getMountedObjectCount();
	for (S32 i = 0; i < mountCount; i++)
	{
		target->getMountedObject(i)->disableCollision();
	}

	Point3F checkPoint = getBoxCenter();
	//getMuzzlePointAI(0, &checkPoint);
	//getBoxCenter();

	bool hit = !gServerContainer.castRay(checkPoint, target->getBoxCenter(), TerrainObjectType | StaticShapeObjectType | StaticObjectType | PlayerObjectType | DynamicShapeObjectType, &rInfo);
	enableCollision();

	for (S32 i = 0; i < mountCount; i++)
	{
		target->getMountedObject(i)->enableCollision();
	}

	if (!hit)
	{
		//only return true if it's our intended target!
		S32 id = rInfo.object->getId();
		if (id == target->getId())
			return true;//<<<<<<<0----------------ALWAYS TRUE WHEN HIDING BEHIND OTHER PLAYERS :(
	}
	return false;
}
Any pointers on what I am doing wrong? I usually script this kinda thing but thought I'd try C++ instead.

//=============================================
//=============================================
edited ... moments after posting ... :roll:
DERP

My console function engineDefine was calling another LOS function and not my custom one here. :lol:

PROBLEM WAS WITH MUPPET AT KEYBOARD

Image
1 post Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest