Understanding vectors/angles

I’m being retarded at the moment, and can’t grasp how to move one vector closer to another.

This is in connection with a third person camera thing I’m working on, where I want the camera to move closer to the player if the camera crosses a wall or entity.

I’ve worked out a trace I do from the original position to the new, and using trace.HitPos as new camera position if trace.Hit returns true.

However, even with the new position, some of the viewport (edges) are inside whatever object was blocking the cam. I.e the player can see through the world or object, potentially working as a weak wallhack.

So, I want to move the vector I am given by trace.HitPos closer to the original vector.



function thirdperson_calculate(ply, pos, angles, fov)
    if canThirdPerson() then
        local view = {}
        view.origin = pos-(angles:Forward()*100)
        view.angles = angles
        view.fov = fov
        local tracedata = {}
        tracedata.start = pos
        tracedata.endpos = view.origin
        local trace = util.TraceLine(tracedata)
        if trace.Hit then
            view.origin = trace.HitPos
        end
        return view
    end
end
hook.Add("CalcView", "thirdperson", thirdperson_calculate)


(Note: On the subject of being retard, I’m also having problems understanding how vectors and angles interact with each other in source engine, or 3d calculations in general, can anyone elaborate with an easy-to-understand tutorial? Or at least a link to one?

I’ve read myself crazy on various wiki pages, both wikipedia, mathworld.wolfram, and gmod’s lua wiki pages, but obscure greek symbols isn’t doing it for me, I’m of a simple mind, I need images.)

(Note2: I’ve already admitted being a retard, but at least I’m a well-read retard, I’ve done my share of searches, and wiki reading before asking - please do not flame me to death for asking, as is apparently customary for this place)

Theres no point to check if the tracer hits something, since if it doesn’t it returns the end vector. Also, I think that hitnormal would work better, since it doesn’t matter how far the camera is when done right, heres the fixed code:[LUA]hook.Add(“CalcView”, “thirdperson”, function(ply, pos, angles, fov)
if canThirdPerson() then
local view, trace = {}, util.TraceLine({start = pos, endpos = pos+ angles:Forward()-100, filter = ply})
view.origin = trace.HitPos+ trace.HitNormal
3
return view
end
end)[/LUA]

[lua]
–move p1 n units closer to p2
p1 = p1+(p2-p1):GetNormal()*n
[/lua]
As for vector math in general I have found Wolfram to explain things in an easier manner than wikipedia and other sites.

Thank you for this. Its not perfect, but its very, very close.
I really like how you compressed that into two lines.