Jump to content

Check object in raycast problems - SOLVED


Steve_Yorkshire

Recommended Posts

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(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


ar130861892168971.jpg

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...