• Player View Bob while sprinting
    25 replies, posted
Hello facepunch! i have a question. i'm working on some SWEPs for my gamemode, and i need to figure out how to make the player's view bob from left to right while sprinting, For more realism in the sweps. Can somebody paste me some example code/ some calls on how to bob the player's view while sprinting?
[url=http://wiki.garrysmod.com/?title=Player.ViewPunch]Player.ViewPunch[/url] should do the trick, works bolth clientside and serverside An Example would be [lua] local ply = LocalPlayer() ply:ViewPunch(Angle(5,0,0)) [/lua] that would make the plays view get smacked up
so maybe you could try setting a new viewpunch var randomly every 5 seconds and applying it?
[QUOTE=LordZZT;30773979][url=http://wiki.garrysmod.com/?title=Player.ViewPunch]Player.ViewPunch[/url] should do the trick, works bolth clientside and serverside An Example would be [lua] local ply = LocalPlayer() ply:ViewPunch(Angle(5,0,0)) [/lua] that would make the plays view get smacked up[/QUOTE] is there any formulas can follow for left then right and such?
Just have it check if the player is moving right or left, not that hard.
it's not supposed to be depending on direction, it's supposed to bob left, then right, as if the player was running, no matter what direction he is going
so can't you check if the player is pressing 'W' then if he is set 2 timers to go on infinite loop and time it so it sets ply:ViewPunch(Angle(5,0,0)) then change it to bob the other way? I can't really explain what I'm thinking so I hope you understood this :P
yeah i understood that. how would i check if a player hit W? or any key in particular for that matter?
[b][url=wiki.garrysmod.com/?title=Gamemode.KeyPress]Gamemode.KeyPress [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]
You are all gay. [b][url=wiki.garrysmod.com/?title=Gamemode.PlayerFootstep]Gamemode.PlayerFootstep [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] [editline]30th June 2011[/editline] Science mad.
[QUOTE=Science;30798772][b][url=wiki.garrysmod.com/?title=Gamemode.KeyPress]Gamemode.KeyPress [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b][/QUOTE] Gamememode calls work inside of sweps? i did not know this.
[QUOTE=Kruel Kramer;30806619]Gamememode calls work inside of sweps? i did not know this.[/QUOTE] Re-read the original post before trying to look smart.
[QUOTE=Science;30806812]Re-read the original post before trying to look smart.[/QUOTE] You make no sense. Can i get a yes or a no on my question?
Sorry i didnt realise you was the op. No they dont. I thought you meant you was making a gamemode and you want it throughout the gamemode, not just in sweps.
[QUOTE=Wizard of Ass;30798939]You are all gay. [b][url=wiki.garrysmod.com/?title=Gamemode.PlayerFootstep]Gamemode.PlayerFootstep [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] [editline]30th June 2011[/editline] Science mad.[/QUOTE] Oh baby I love you so much, I could totally agree and came all over yourself. Don't listen to Science he is as dumb as an brick. [highlight](User was banned for this post ("Flaming" - Autumn))[/highlight]
[QUOTE=Science;30806938]Sorry i didnt realise you was the op. No they dont. I thought you meant you was making a gamemode and you want it throughout the gamemode, not just in sweps.[/QUOTE] Yeha, i'm trying to make this SWEP Sided. i saw that the customizeable sweps had a feature like that, but i looked all over the lua and i couldnt find the actual code for it.
[QUOTE=RetTurtl3;30808824]Oh baby I love you so much, I could totally agree and came all over yourself. Don't listen to Science he is as dumb as an brick. [highlight](User was banned for this post ("Flaming" - Autumn))[/highlight][/QUOTE] :3:
Well at least the admins are doing their job on player reports as well. I just reported him to Autumn and within 5 minutes hes banned. Winning :zoid:
For the record, I only knew about it because somebody PMed me. Remember, it takes two reports from different people before it becomes visible to mods.
[QUOTE=Science;30809850]Well at least the admins are doing their job on player reports as well. I just reported him to Autumn and within 5 minutes hes banned. Winning :zoid:[/QUOTE] Damn patsy. :argh: [editline]30th June 2011[/editline] He might gotten a longer one if he got mad.
[QUOTE=Kruel Kramer;30786839]is there any formulas can follow for left then right and such?[/QUOTE] use sine/cosine functions for left/right movement. your function in lua would look kinda like [code] math.sin( CurTime() ) [/code] It's up to you to apply it, but if you apply that to one of your view angles every frame you'll find it waving up and down. For more wave multiply the entire formula by something greater than one, for less, multiply it by a number between zero and one. For a faster wave multiply CurTime() INSIDE math.sin() by a number greater than one. For a slower wave multiply it by a number between zero and one. Although for a truly realistic viewbobbing, you'll want a figure-eight pattern which is pretty easy to replicate using parametric equations.
[QUOTE=TZScribblez;30814845]use sine/cosine functions for left/right movement. your function in lua would look kinda like [code] math.sin( CurTime() ) [/code] It's up to you to apply it, but if you apply that to one of your view angles every frame you'll find it waving up and down. For more wave multiply the entire formula by something greater than one, for less, multiply it by a number between zero and one. For a faster wave multiply CurTime() INSIDE math.sin() by a number greater than one. For a slower wave multiply it by a number between zero and one. Although for a truly realistic viewbobbing, you'll want a figure-eight pattern which is pretty easy to replicate using parametric equations.[/QUOTE] This would be hella easy for me if i've ever attended a trigonometry class, which i havent ._. Is it trigonometry or is it calculus?
[QUOTE=TZScribblez;30814845]use sine/cosine functions for left/right movement. your function in lua would look kinda like [code] math.sin( CurTime() ) [/code] It's up to you to apply it, but if you apply that to one of your view angles every frame you'll find it waving up and down. For more wave multiply the entire formula by something greater than one, for less, multiply it by a number between zero and one. For a faster wave multiply CurTime() INSIDE math.sin() by a number greater than one. For a slower wave multiply it by a number between zero and one. Although for a truly realistic viewbobbing, you'll want a figure-eight pattern which is pretty easy to replicate using parametric equations.[/QUOTE] Actually what you say would give async movement it would be very irritating, you have to sync your viewbobbing with the footstep sound which in all honestly is easy as piss.
It's trigonometry. It's nothing too advanced, so you might be able to understand this concept with a little playing around and experimentation. The base "parent function" we're looking at here is y=sinx. We'll add a few extra variables in there to play with the amplitude (height, or "intensity") and the period ( wavelength/speed ), making it y=A*sin(kx). Sine is a function that oscillates between -1 and 1. It goes about in a wave, repeating itself infinitely. If you've ever graphed a function before, graphing y=sinx simply looks like a wave. In order to use this in-game, though, you have to increase your value of x constantly, in order to get a new y value. Basically you're changing x over and over to "follow" the path of the wave. The easiest way to get a constantly changing x is to use CurTime(), since time isn't gonna stop or anything ;) ... Simply call math.sin( CurTime() ) every frame and use the result as one of your viewangles, and you'll have a view that bobs up and down. Referring to the "expanded" function, y=A*sin(kx), increasing A greater than one makes the bob bigger and making it a fraction makes it smaller. Negative values will act similarly to positive values. K is the same way, except it makes it faster/slower instead of bigger/smaller. The thing about parametric equations is calculus though, I wouldn't recommend trying to mess with it unless you're up for quite a bit of wikipedia studying to figure them out :P I'm terrible at explaining stuff like this but I hope that was at least a little enlightening. Viewpunches are quite a bit easier but I like the results of sine. [QUOTE=Wizard of Ass;30828985]Actually what you say would give async movement it would be very irritating, you have to sync your viewbobbing with the footstep sound which in all honestly is easy as piss.[/QUOTE] It's pretty easy to sync it as a function of your movement speed, once you realize how the result of GetRunSpeed() or (whatever the function was) relates to the rate of steps. I think it's actually steps per minute but I may be misremembering, been a while since I messed with that.
[QUOTE=Kruel Kramer;30828547]This would be hella easy for me if i've ever attended a trigonometry class, which i havent ._. Is it trigonometry or is it calculus?[/QUOTE] Search for sine wave modulation, its quite easy to understand. And its trigonometry. Oh and just saying, lua uses radians for sin and cos not degrees.
[QUOTE=Wizard of Ass;30829011]Search for sine wave modulation, its quite easy to understand. And its trigonometry. Oh and just saying, lua uses radians for sin and cos not degrees.[/QUOTE] doesn't particularly matter since sine and cosine return values and not angles, the only angle you deal with is x, and that's determined by CurTime(). It'd definitely matter for asin or acos though.
Sorry, you need to Log In to post a reply to this thread.