UP/DOWN "Aim assist" for top down

i need to find a way to create an up down aim assist for when the target is higher or lower then the player

I am working on a top down gamemode and have no way to aim up or down (from the view of the player entity) so therefor i need a small aim assist in order to lock onto a target and aim at them without having the aim assist effect the left and right movement directions

I have tried findinbox, and cant seem to make it target above or below the player entity(never used findinbox before)

Any direction pointing would be appreciated

What I would do is make it so there’s a consistent trace from the player through the world towards players. If it hits a player, it checks to see if it can reach the head, torso, and legs in that order. If it can, it forces the player to aim at that vector.

Whether or not this would be optimized would be a different story entirely. I’m not sure how else it would be done, but perhaps that’s a start.


local diff = (target:GetPos() + target:OBBCenter() - player:GetShootPos()):GetNormal()

if (diff:Dot(player:GetAimVector()) > 0.95) then
    local oAng = player:EyeAngles()
    local newPitch = (target:EyePos() - player:GetShootPos()):Normalize():Angle().p
    local shootAng = Angle(newPitch, oAng.y, oAng.z)
end

Idea is if you’re looking near a target (mess around with the 0.95 until it works good) you can set the pitch of the player’s shoot angles so he is aiming at the targets’s head or wherever (change target:EyePos() to where you want them to aim, and you’d also wanna trace the target to make sure you can see him too). Unfinished code ofc since I don’t know how you’re gonna implement it, but the core ideas are there, hopefully I didn’t fuck up.

My main obstical is finding targets in the 2d straight ahead. But only finding the tragets i am aiming at. I guess i could trace from the player at a few different angles but that seems really heavy for something so simple

Like I said, I would use a trace that ignores the world and non-players. Grab the player (if there is one) and then check to see if the player can actually shoot the head, torso, or feet, in that order. If it can see anything, it changes the pitch to hit that attachment. Either that, or find some way to make the player look at the first angle that allows them to see the player.

would findinbox not be more efficient?

[editline]21st January 2016[/editline]

OH,., seems to make a box between the two positions and when that is at an angle… lol doesnt work to well

[editline]21st January 2016[/editline]

so why not findincone? with a thin radius

[editline]21st January 2016[/editline]

findincone is still broken? what has it been 3 years…?

Just realized your code had a check for closeness, i could just find in sphere and then check the pos with your code,

OK! this mostly works, until you get multiple enemies then it locks on to one enemy (even after death?(used isvalid check on the npc before looking for position)) and doesnt switch from them untill the npc dies

[editline]22nd January 2016[/editline]

[lua]local targetang = 0

local function findtarget(target)
if target then
local diff = (target:GetPos() + target:OBBCenter() - LocalPlayer():GetShootPos()):GetNormal()
if (diff:Dot(LocalPlayer():GetAimVector()) > .95) then
–print(target:GetClass()…“1”)
local oAng = LocalPlayer():EyeAngles()
–print((target:EyePos() - LocalPlayer():GetShootPos()):Angle())
local newPitch = ((target:EyePos() - LocalPlayer():GetShootPos()):Angle())

		local shootAng = Angle(newPitch.p, oAng.y, oAng.z)
		--print(shootAng.p)
		return shootAng
	end
end

end

	--findinbox makes a box between two points (large box at angles)

function aimassist( ply, pos, angles, fov, nearZ, farZ)
local aiment = ents.FindInSphere(pos, 600)
local oldaim = EyeAngles()

	for v, k in pairs(aiment) do
		if k:IsNPC() and k:IsValid() then
				targetang = findtarget(k)
				print(targetang)
				ply:SetEyeAngles(targetang or  Angle(0,oldaim.y, oldaim.z))
		end	
	end

end

hook.Add( “CalcView”, “aimassist”, aimassist )
[/lua]

What about a screen clicker, basically you aim exactly where your mouse is pointing?

Anyone have an idea on that?

This is one of the few posts for it that i can find, yet i cant get it to work :confused: (5 years old)

https://www.facepunch.com/threads/891702-Mouse-position-to-world-vector-from-a-custom-origin

One technique I’ve used in other programming languages to select 3D objects by clicking on the screen is:

  1. Render collisionmodels of any selectable objects to a surface (with a solid white texture)
  2. Apply a color to each model based on their unique ID
  3. Get the color of the position of the surface where the mouse pointer is located
  4. Convert the color back to an object ID, and select that object ID if it exists.

(the surface which these objects are rendered to is never seen by the player)

I have no clue if this would be possible with lua in Garry’s mod… probably not, but I thought I’d share it anyway. Who knows, might spark an idea

You should be doing this in CreateMove, and at the moment it acts like an aimbot. If you want the player to move their crosshair away from the target just do like a threshhold check on MouseX and MouseY from CUserCMD in CreateMove, so that it only aim assists if their mouse is slow enough, allowing them to break free. Alternatively you could lerp their shootangle instead of just setting it, and if you did that at the right speed you would be able to break free from the .95 dot check, but finding the right lerp speed for it still to be effective might be a challenge. Just mess around with stuff.

pulling away is easy bc i have the left right movement free, the main issue i am having is it doesnt get the closes to the shoot angle instead i currently have it target the closest enemy to the player

Try changing this


local diff = (target:GetPos() + target:OBBCenter() - player:GetShootPos()):GetNormal()

To this


local diff = (target:GetPos() - LocalPlayer():GetShootPos()):GetNormal()
diff.z = LocalPlayer():GetAimVector().z

This completely undoes what i am trying to do…

How so? That makes it so when aiming towards players it ignores their elevation so it can check the dot of the vector in a 2D fashion, like from top down how you want it. Then when setting the shoot angles it sets the pitch to aim up/down at them. All guchi no?

no i dont think you understand what i am trying to do…

Either this (horrible drawing i know)

http://i.imgur.com/HDaznPb.png[/t]

Or this
[t]http://i.imgur.com/kytJ2VA.png

(aim at head height not left or right)

[editline]22nd January 2016[/editline]

This is what i have atm and it MOSTLY works, the only issue i have found is that if there are multiple targets it only gets the closest target to aim at instead of the closest to my aim trace

[lua]local targetang = nil

local function findtarget(target)
if target then
local diff = (target:GetPos() + target:OBBCenter() - LocalPlayer():GetShootPos()):GetNormal()
if (diff:Dot(LocalPlayer():GetAimVector()) > .95) then
local oAng = LocalPlayer():EyeAngles()
local newPitch = ((target:EyePos()- target:OBBCenter() - LocalPlayer():GetShootPos()):Angle())
local shootAng = Angle(newPitch.p, oAng.y, oAng.z)
return shootAng
end
end
end

function FindNearestEntity( className, pos, range )
local nearestEnt;
for i, entity in ipairs( ents.FindByClass( className ) ) do
local distance = pos:Distance( entity:GetPos() );
if( distance <= range ) then
if entity and entity:IsValid() and entity:IsNPC() then
nearestEnt = entity;
range = distance;
end
end
end
return nearestEnt;
end

function aimassist( ply, pos, angles, fov, nearZ, farZ)
local aiment = FindNearestEntity(“npc_*”,pos, 600)
local oldaim = EyeAngles()
if aiment and aiment:IsValid() and aiment:IsNPC() then
targetang = findtarget(aiment)
end
if targetang != nil then
ply:SetEyeAngles(targetang)
else
ply:SetEyeAngles(Angle(0,oldaim.y, oldaim.z))
end

end

hook.Add( “CalcView”, “aimassist”, aimassist )[/lua]

aiment is getting the nearest entity to “pos”. I thought pos was the camera pos? That doesn’t seem like the functionality you want.

it is basically the same position as the player as far as i can tell. i dont want the closest to the player though i want the closest to the point that the trace passes through

[editline]23rd January 2016[/editline]

this is in another portion of the code to make it topdown
[lua]
function MyCalcView( ply, pos, angles, fov, nearZ, farZ)
local view = {}
view.origin = pos + Vector(0,0,500)
view.angles = Angle(90,0,0)
view.fov = 90
view.zfar = farZ
view.znear = nearZ
local trend2 = LocalPlayer():GetEyeTrace().HitPos
view.drawviewer = true
return view
end

hook.Add( “CalcView”, “MyCalcView”, MyCalcView )[/lua]

So you tried that code I gave you and it didn’t work? And again, CreateMove…

why not make the player always aim towards a point about 30-40 units above the ground beneath their cursor? that way if somebody is standing on a ledge above you and you put your cursor above them your bullets will fly upwards to hit them
only thing is you’d most likely need some kind of crosshair indicator to tell you if you can or can’t actaully fire at that spot so you dont end up trying to shoot people up on ledges and hitting the wall instead cos they are too far back