# Aim assist (GoldenEye/Perfect Dark)

Anyone remember how the aim assist works in GoldenEye on n64? Where the gun model would point at an enemy if he's within a certain area in your field of view. I'm trying to do something like that but have hit a wall. I'm pretty inexperienced in Unity 3D and using this project as a way to learn the ropes.

I've currently got it so that if you're in range of an enemy (facing him or not), your gun model will rotate towards that enemy. But I need to do it so that only happens if that enemy is in front of your facing direction and near the centre of the screen.

Any tips or pointers how to do this? Do I need do a raycast in direction of camera and do some math to figure out which enemy is nearest? If so what Math functions would I need to look into?

• Aim assist is actually used by almost every first person shooter on consoles (due to the difficulty of aiming precisely with a gamepad) and is also available on most first person shooters on PC as an option. Aug 21, 2016 at 12:52
• Doing many different implementations is possible and it depends on your camera code etc.
– ave
Aug 21, 2016 at 13:23

1. Use Quaternion targetDirection = Quaternion.LookRotation(target.transform.position - player.transform.position) to calculate the direction of all eligible targets.
2. Calculate how far the aiming is off for each target: float aimAngleWrongness = Quaternion.Angle(player.transform.rotation, targetDirection)
3. Pick the target with the lowest aimAngleWrongness. Optionally you can also take the distance to the enemy into account to prefer closer targets to those further away. The distance can be calculate with (enemy.transform.position - player.transform.position).magnitude.
4. You can now implement the actual aiming behavior in many different ways. You can simply move the crosshair without moving the sight direction, you can move the sight direction immediately (very simple to do but might feel disorienting for the player) or you can do it smoothly with Quaternion.Slerp between targetDirection and player.transform.rotation.