Left 4 Dead 2

Left 4 Dead 2

View Stats:
How can I use TraceHull in L4D2?
I was looking for a way to detect a wider area than TraceLine, and I came across TraceHull, but I'm not sure how to use it. or Is there a way to use TraceLine in a manner similar to TraceHull?
< >
Showing 1-8 of 8 comments
TraceHull function exists in other source engine games, but not l4d2. :(

You could probably simulate TraceHull by making a new function using TraceLine, but I haven't thought of a good way to implement it.
PLUIE May 8 @ 9:32pm 
@Interneted
In that case, would it be possible to create a temporary object at c_thirdpersonshoulderoffset and set its GetOrigin?

::GetCameraLookDistanceTo <- function(targetVec) { local cam = Entities.FindByName(null, "camera"); local trace = { start = cam.GetOrigin(), end = cam.GetOrigin() + cam.GetAngles().Forward().Scale(999999), ignore = cam, mask = 1174421507 }; TraceLine(trace); return (trace.pos - targetVec).Length(); }
If this is feasible, I believe this script could be used to generate a camera (or an arbitrary object) at the c_thirdpersonshoulderoffset value and calculate the distance to the crosshair.

This would be a huge help in developing a third-person aiming mode

I have created a beta mod that uses player.EyePosition to align cam_idealyaw with the aiming position in third-person view. If you're interested in trying it out or providing feedback on possible improvements, I’d be happy to share the mod with you
I wonder if probably what you're looking for is something like spawning an entity to act like a camera. If that's the case, you can use "info_target" with a specific targetname, like this:
local cam = SpawnEntityFromTable("info_target", { targetname = "camera_" + player.GetPlayerName() });
That "info_target" will act as the camera. Add that code to replace your "local cam".

& if it's just a temporary object, you might need to set some conditions to remove it with "cam.Kill()" when a player no longer uses it, to do a regular cleanup on the spawned "info_target" entity.
Last edited by kurochama; May 8 @ 11:12pm
PLUIE May 10 @ 4:40am 
@kurochama
I implemented this method, but the screen movement wasn't smooth, so I had to give up. Thank you for your advice
Originally posted by PLUIE:
@Interneted
I successfully made TraceLine function like TraceHull. Look forward to a new third-person correction addon that I'll be uploading to the workshop
Ah nice one, I just saw the messages after I got back from my trip.

If you don't mind, may you share the function on how it looks like?
PLUIE May 10 @ 9:01am 
Originally posted by Interneted:
Originally posted by PLUIE:
@Interneted
I successfully made TraceLine function like TraceHull. Look forward to a new third-person correction addon that I'll be uploading to the workshop
Ah nice one, I just saw the messages after I got back from my trip.

If you don't mind, may you share the function on how it looks like?

@Interneted
I successfully made TraceLine function like TraceHull. Look forward to a new third-person correction addon that I'll be uploading to the workshop

-Original TarceLine code:
::GetLookingLocation <- function(player) { local startPt = player.EyePosition(); local endPt = startPt + player.EyeAngles().Forward().Scale(999999); local m_trace = { start = startPt, end = endPt, ignore = player, mask = 1174421507}; TraceLine(m_trace); return m_trace.pos; }

-TraceLine code that functions similarly to TraceHull
::GetBestLookingDistance <- function(player) { local eyePos = player.EyePosition(); local viewAngles = player.EyeAngles(); local forward = viewAngles.Forward(); local up = viewAngles.Up(); local right = up.Cross(forward); right.Norm(); local bestFraction = 1.0; local bestPos = null; for (local y = -1; y <= 1; y++) { for (local x = -1; x <= 1; x++) { local offsetDir = forward + right * x * 0.02 + up * y * 0.01; offsetDir.Norm(); local traceEnd = eyePos + offsetDir * 999999; local trace = {start = eyePos,end = traceEnd,ignore = player,mask = 1174421507}; TraceLine(trace); if (trace.fraction < bestFraction) { bestFraction = trace.fraction; bestPos = trace.pos; } } } if (bestPos != null) { return (bestPos - eyePos).Length(); } return 999999; // fallback }
Originally posted by PLUIE:
@Interneted
I have already applied this method to the existing thirdperson aim fix MOD workshop Link
Probably you can add more animated previews about this update on that mod later, so people will be able to see some new changes you did after modifying the Traceline.
PLUIE May 10 @ 10:22pm 
Originally posted by kurochama:
Originally posted by PLUIE:
@Interneted
I have already applied this method to the existing thirdperson aim fix MOD workshop Link
Probably you can add more animated previews about this update on that mod later, so people will be able to see some new changes you did after modifying the Traceline.
https://steamcommunity.com/sharedfiles/filedetails/?id=3412799841

I have attached an image that clearly shows the improvements. This should be enough explanation for general users
< >
Showing 1-8 of 8 comments
Per page: 1530 50