I'm trying to be able to rotate my view around the player in a full 360 using the left and right keys. I need a little help with manipulating the vectors and angles.. this is what I did.
[video=youtube;9f1O0pCjp5o]http://www.youtube.com/watch?v=9f1O0pCjp5o[/video]
Here's what I did just to show my idea.
[lua]
--CalcView hook
view.angles = LocalPlayer().oldAngles or Angle(45, 0, 0)
view.origin = pos + Vector(-250, 0, 200) + LocalPlayer().addedOrigin
if(input.IsKeyDown(KEY_LEFT)) then
SetCustomAngles(view.angles, 0, -1, 0)
SetCustomOrigin(2.5, 3, 0)
end
if(input.IsKeyDown(KEY_RIGHT)) then
SetCustomAngles(view.angles, 0, 1, 0)
SetCustomOrigin(-2.5, -3, 0)
end
--Seperate Functions
function SetCustomAngles(curAng, pAng, yAng, rAng)
LocalPlayer().oldAngles = curAng + Angle(pAng, yAng, rAng)
end
function SetCustomOrigin(xOrig, yOrig, zOrig)
LocalPlayer().addedOrigin = LocalPlayer().addedOrigin + Vector(xOrig, yOrig, zOrig)
end
[/lua]
So I'm thinking that what you're trying to do is an Orbit Camera.
Here's something you might be interested in:
[code]local m_Angles = Angle( 25, 0, 0 );
local m_fRotateSpeed = 1;
local m_fZoom = 256;
hook.Add( "CalcView", "OrbitCamera", function( player, vOrigin, aAngles )
if ( input.IsKeyDown( KEY_LEFT ) ) then
m_Angles:RotateAroundAxis( Vector( 0, 0, 1 ), -m_fRotateSpeed );
elseif ( input.IsKeyDown( KEY_RIGHT ) ) then
m_Angles:RotateAroundAxis( Vector( 0, 0, 1 ), m_fRotateSpeed );
end
local aBackward = ( m_Angles:Forward() * -1 ):Angle();
local aForward = ( aBackward:Forward() * -1 ):Angle();
vOrigin = Vector( m_fZoom, 0, 0 );
vOrigin:Rotate( aBackward );
vOrigin = vOrigin + LocalPlayer():GetPos(); -- Add the vector you want to orbit around.
return { origin = vOrigin, angles = aForward };
end );[/code]
If you don't want it to go through walls, you could do a basic TraceLine from the point you're orbiting around, to the camera's origin. I'm sure you're smart enough to figure out the wrest. :)
Picture with zoom of 196:
[t]http://cloud-3.steampowered.com/ugc/1047377791007084771/B9FE1D949C9A7ADA3B41DE2F93359F2741841906/[/t]
([URL="http://facepunch.com/showthread.php?t=855090&p=18758852&viewfull=1#post18758852"]Click here for an explanation of this method[/URL])
Thank you so much! I'm going to try and figure out how the hell this works(I hate vectors) before I stop it from clipping through walls.
Sorry, you need to Log In to post a reply to this thread.