TLDR: World2Screen the enemy, get location of enemy relative to player’s screen, write values to player’s viewangles.
mouse_event: Same theory, different execution. Instead of writing to the viewmatrix, the mouse is controlled externally using something like mouse_event. Most programming languages will have some sort of class/API that can be used to achieve this.
Check these out for more info on matrices, and the concept of the view matrix: http://www.songho.ca/opengl/gl_anglestoaxes.html , http://www.codinglabs.net/article_world_view_projection_matrix.aspx.
Check this out for more info on how World to Screen works: https://docs.unity3d.com/ScriptReference/Camera.WorldToScreenPoint.html
Yes. Let’s look at an example. In the image below, the blue X represents the starting location of the player’s crosshair, the red X represents the target location:
Now this is what happens if we write directly to the player’s view angles (or in this case, cursor position). Black represents the path the aimbot takes:
There is no path! The cursor will ‘jump’ from source to destination. Obviously, no human is capable of doing this.
One way of generating a path is to use Linear Interpolation (lerp).
LERP works by taking an initial position and a destination, and generating a straight line between the two points.
Using the previous example, we will get a result similar to:
Is this good? Is it human-like? Well, try moving your mouse along the same path. Are you able to mimic the line generated by the linear interpolation? Unlikely. You are likely moving in a subtle curve like the image below:
Now in a video game, it’s a lot harder to look at crosshair movement and know it’s a perfectly straight line, so for most purposes, this is fine.
While a slow-moving lerp aimbot will work fine, we can do better. We can calculate a path between source and target using a Bézier curve. A Bézier curve is a parametric curve frequently used in computer graphics.
The images below depict the path generated by a quadratic, and cubic Bézier curve respectively.
In theory, the higher order we use, the more ‘humanized’ the aim will look. We can construct a Bézier curve of order n as follows:
This is all really cool in theory, but does it work in practice?
Well, does anyone really move their mouse like this?
Because we are using these curves to create an aimbot, we have to consider the target moving. Specifically, the target can move during calculations. This will, without a doubt, completely screw with the curve.
Possible solutions include:
It’s a neat idea in theory, but would require some significant tweaking to make it actually look human. Notably, depending on the control points selected, the mouse movement can range between passable and ridiculous. Furthermore, the addition of movement complicates things significantly. I’d guess that there are probably much more effective methods than using a Bézier Curve.