I'm trying to make an over-the-shoulder perspective but I've run into some issues: when I move the camera to look down or up it goes sideways, when I'm close and facing a wall it goes really far to the left, and it doesn't aim where it's suppose to. Any help or improvements would be appreciated.
[code]tp.ThirdPerson = function(ply)
if !(tp.Active and ply:Alive()) then return end
local origin = ply:EyePos()
local angles = ply:EyeAngles()
local view = {drawviewer = true}
local trace = {
start = origin,
endpos = origin + (angles:Forward() * tp.Behind) + (angles:Right() * tp.Right),
maxs = max,
mins = min,
mask = MASK_NPCWORLDSTATIC,
ignoreworld = ply:GetMoveType() == MOVETYPE_NOCLIP,
}
local aimAng = (ply:GetEyeTraceNoCursor().HitPos - ply:GetShootPos()) - (angles:Right() * tp.Right)
aimAng = aimAng:Angle()
aimAng.p = math.NormalizeAngle(aimAng.p)
aimAng.y = math.NormalizeAngle(aimAng.y)
aimAng.r = 0
view.origin = util.TraceHull(trace).HitPos
view.angles = aimAng
return view
end
hook.Add("CalcView", "tp_ThirdPerson", tp.ThirdPerson)
[/code]
- bump -
- bump -
I think your problem is probably in this line:
[lua]local aimAng = (ply:GetEyeTraceNoCursor().HitPos - ply:GetShootPos()) - (angles:Right() * tp.Right)[/lua]
Firstly, you should probably replace [b](ply:GetEyeTraceNoCursor().HitPos - ply:GetShootPos())[/b] with [b][url=http://wiki.garrysmod.com/page/Player/GetAimVector]ply:GetAimVector()[/url][/b]. Secondly, I have no idea what [b]tp.Right[/b] is but I'm guessing it's the offset for over-the-shoulder - I don't think this is how you should do it but I can't really tell because I don't have the rest of your code.
Full code would help. A video demonstrating the behavior and issues would be even better.
Sorry, you need to Log In to post a reply to this thread.