Aimbot C# AssaultCube Hack
23:16 03 Apr 2026

My aimbot is locking onto the enemy incorrectly and sometimes gets stuck aiming at a wall instead of the target.

I think my angle calculation or target selection might be wrong, but I’m not sure what exactly is causing this issue.

Can someone help me understand why the aim locks to walls and how I can fix it?

        static void Aimbot(IntPtr localPlayer, IntPtr entityList)
        {
            float myX = Mem.ReadFloat(localPlayer + Offset.Pos_X);
            float myY = Mem.ReadFloat(localPlayer + Offset.Pos_Y);
            float myZ = Mem.ReadFloat(localPlayer + Offset.Pos_Z);

            IntPtr closest = IntPtr.Zero;
            float closestDistance = float.MaxValue;

            for (int i = 0; i <=32; i++)
            {
                IntPtr entity = Mem.ReadPointer(entityList + i * 0x4);

                if (entity == IntPtr.Zero)
                    continue;

                if (entity == localPlayer)
                    continue;

                int hp = Mem.ReadInt(entity + Offset.Health);

                
                if (hp <= 0 || hp > 100)
                    continue;

                float ex = Mem.ReadFloat(entity + Offset.Pos_X);
                float ey = Mem.ReadFloat(entity + Offset.Pos_Y);
                float ez = Mem.ReadFloat(entity + Offset.Pos_Z);

                float dx = ex - myX;
                float dy = ey - myY;
                float dz = ez - myZ;

                float distance = (float)Math.Sqrt(dx * dx + dy * dy + dz * dz);

                if (distance < closestDistance)
                {
                    closestDistance = distance;
                    closest = entity;
                }
            }

            if (closest == IntPtr.Zero)
                return;

            float tx = Mem.ReadFloat(closest + Offset.Pos_X);
            float ty = Mem.ReadFloat(closest + Offset.Pos_Y);
            float tz = Mem.ReadFloat(closest + Offset.Pos_Z);

            float dx2 = tx - myX;
            float dy2 = ty - myY;
            float dz2 = tz - myZ;
       
            float yaw = (float)(Math.Atan2(dy2, dx2) * 180.0 / Math.PI);
            float dist = (float)Math.Sqrt(dx2 * dx2 + dy2 * dy2);
            float pitch = (float)(-Math.Atan2(dz2, dist) * 180.0 / Math.PI);

            Mem.WriteFloat(localPlayer + Offset.yaw, yaw);
            Mem.WriteFloat(localPlayer + Offset.pitch, pitch);
        }
c#