• 2d mouse aim?
    5 replies, posted
hey, i have a basic understanding of lua.. im making a 2d sidescrolling gamemode. But how do you make the charecter aim only on a 2d perspective (not aiming behind or in front but only up, down, left, and right). It would be a great help if you guys can aid me thanks!
It is fairly simple: If the x coordinate of the mouse is to the left of the center, face left, else face right. Set the player's aim pitch to match the angle of the cursor from the origin. [code] local ang, v, w, x, y ang = cmd:GetViewAngles( ) x, y = gui.MousePos( ) v, w = ScrW( ) * .5, ScrH( ) * .5 ang.p = math.deg( math.atan2( v - x, w - y ) ) ang.y = ( x < v ) and 90 or -90 cmd:SetViewAngles( ang )[/code] The same logic can be applied to the yaw rather than the pitch to do a top-down camera where the player would rotate to face the cursor. You'd do this in CreateMove on the client. The angles for the yaw ( .y ) would need to be determined ahead of time based on the map, of course, and could even be changed on the fly so you could pan the camera around the map to create interesting perspective changes.
thanks, would you do the 2d cam in the CreateMove hook too?
You'd update the position of where you want the camera to be in CreateMove, but you'd probably position it in CalcView.
Yeah; CreateMove is fantastic for certain operations not available in CalcView. Example, you can properly check mouse-wheel movement from CreateMove, button presses, mouse presses, etc.. You can use all of that information to offset it in CreateMove, then display it using CalcView.
sorry to be "that guy" but can you elaborate a bit more on how you do the 2d aim, sorry.. sort of a noob. and its the first time ive used the calcview method [editline]5th May 2014[/editline] [QUOTE=Kogitsune;44717400]It is fairly simple: If the x coordinate of the mouse is to the left of the center, face left, else face right. Set the player's aim pitch to match the angle of the cursor from the origin. [code] local ang, v, w, x, y ang = cmd:GetViewAngles( ) x, y = gui.MousePos( ) v, w = ScrW( ) * .5, ScrH( ) * .5 ang.p = math.deg( math.atan2( v - x, w - y ) ) ang.y = ( x < v ) and 90 or -90 cmd:SetViewAngles( ang )[/code] The same logic can be applied to the yaw rather than the pitch to do a top-down camera where the player would rotate to face the cursor. You'd do this in CreateMove on the client. The angles for the yaw ( .y ) would need to be determined ahead of time based on the map, of course, and could even be changed on the fly so you could pan the camera around the map to create interesting perspective changes.[/QUOTE] sorry to be "that guy" but can you elaborate a bit more on how you do the 2d aim, sorry.. sort of a noob. and its the first time ive used the calcview method
Sorry, you need to Log In to post a reply to this thread.