Jump to content

GetPedTargetCollision without targeting


redditing

Recommended Posts

My goal is simple, after using GetPedCollisionTarget, I want it to return 3 numbers that correspond to the coordinates of the target that has collision detection, but for this function to return something, you must first aim the weapon. And here is the problem because when the player is aiming, the crosshair is somewhere close but not in the center of the center, and I want to get the coordinates of the target in the center, not somewhere nearby. And here comes the question, is it possible to make GetPedCollisionTarget work but without aiming the weapon? PLEASE HELP

Link to comment
  • Discord Moderators

If you want to get the target in the center of the screen, you can use getCameraMatrix. It returns the camera position and lookat position, which is a unit vector from the camera position, so you can easily multiply it to get a point further out.

Made the following so you can see if thats what you need.

local scrW, scrH = guiGetScreenSize()
local maxTargetDistance = 100
addEventHandler("onClientPreRender", root,
	function()
		local cx, cy, cz, lx, ly, lz = getCameraMatrix()

		local px = cx + (lx - cx) * maxTargetDistance
		local py = cy + (ly - cy) * maxTargetDistance
		local pz = cz + (lz - cz) * maxTargetDistance
		
		local hit, hx, hy, hz, hitElement = processLineOfSight(cx, cy, cz, px, py, pz, true, true, true, true, true, false, false, false, localPlayer)
		
		dxDrawRectangle(scrW/2 - 5, scrH/2 - 5, 10, 10)
		
		if hit then
			dxDrawLine3D(hx, hy, hz + 1, hx, hy, hz)
		end
	end)

 

  • Like 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...