Game Development Community

Best Implementation for Auto Aiming?

by Chad Kilgore · in General Discussion · 11/20/2009 (11:35 am) · 6 replies

I am trying to determine the best way to implement "auto-aiming". I put auto aim in quotes because it is not intended to be used with weapons, but instead with object interaction. There would be an interaction zone defined in screen space (assume half the size of the screen and centered). When an interactive entity is (a) within the zone in screen space, (b) within a defined range of the player, and (c) closest to the center of the screen - used when multiple entities are in the zone simultaneously, then the reticule auto aims to that entity and an interaction icon displays.

Does anybody have any suggestions on how to implement this feature gracefully?

#1
11/20/2009 (1:24 pm)
some resource that at this time not remember, have the auto aiming feature, search for enhanced projectiles
#2
11/20/2009 (6:09 pm)
You'd probably want to do something client-side for this... have a look at how GuiCrossHairHud is implemented, specifically the render function that uses a raycast to get information about a hit object. It might be useful to search for some interaction crosshairs to get a little more familiar with the system.
Then I guess your specific design can just be a case of doing a radius search from the player, then finding the closest object within the specified angle (use the dot product for that).
The one difficulty might be making sure the entities are in a rectangular zone. Maybe a better idea would be to look at GuiShapeNameHud instead of CrosshairHud. See how that finds objects and determines whether they're inside the HUD bounds.
#3
11/21/2009 (12:37 am)
I am trying to recreate the cursor system from "Sherlock Holmes versus Jack the Ripper". I will certainly look into GuiShapeNameHud. It looks extremely promising. Thanks.
#4
11/29/2009 (7:33 pm)
I started modifying the GuiShapeNameHud. For the most part I think it works out pretty well (I'm not sure if my closest entity to the GUI's center is correct). I started by displaying names over the characters that can interacted with. This is approximately line 246.

// Render the shape's name
				if (mShowSingle)
				{
					if (NULL == control)
						continue;

					Point2I projVect = mCenter - projection;
					F32 projDist = mSqrt((F32)(projVect.x * projVect.x) + (F32)(projVect.y * projVect.y));

					if (NULL == mShape || (projDist <= mProjDist && control->distanceTo(shape->getPosition()) <= control->distanceTo(mShape->getPosition())))
					{
						mShape = shape;
						mProjection = projection;
						mProjDist = projDist;
					}
				}
				else
				{
					if (mShowName)
						drawName(projection, shape->getShapeName(), opacity);
					if (mShowBitmap)
						drawBitmap(projection);
				}
			}
		}
	}

	if (mShowSingle)
	{
		if (NULL != mShape)
		{
			if (mShowName)
				drawName(mProjection, mShape->getShapeName(), 1.0f);
			if (mShowBitmap)
				drawBitmap(mProjection);
		}
	}

I am having problems trying to figure out where I should place the icon. I'm thinking that it might be easiest to extend ShapeBase to allow every entity to have a unique icon. But then every ShapeBase would have to spawn a GuiBitmapCtrl if it is using an icon. This just seems heavier than it needs to be.

Thoughts for anybody?
#5
11/30/2009 (9:27 pm)
Quote:But then every ShapeBase would have to spawn a GuiBitmapCtrl if it is using an icon. This just seems heavier than it needs to be.
Don't quite understand what you're getting at here. What I would do is add a member to ShapeBase that stores the file path for a bitmap. Then change drawBitmap to take a file path as a parameter, and draw that bitmap instead of something standard. So it'd be something like
drawBitmap(projection, shape->getBitmapPath());
#6
11/30/2009 (10:10 pm)
That is what I meant to say, but only far less eloquently. I will also be adding Icon Extent for the GuiShapeNameHud, so that all icons that it displays will be the same size.