Rick Posted January 9, 2014 Share Posted January 9, 2014 I'm not a math guy by any means, but I'm working on head bobbing in the FPS script. I figured using sine was the perfect way to get this. I have it working, sort of. I need it to always start going down first. I'm trying to find just the right values to time it with the footstep sounds and those sounds happen right away when moving. When the bob is down right away when I start walking seems to be the best results. Any suggestions on how to make this always start going down first would be great. I thought the phase was supposed to do this but it doesn't always seem to be the case if playerMovement.z == 0 then newCameraPos.y = playerPos.y + self.eyeheight else local amplitude = .10 local frequency = 1.18 local phase = 90 newCameraPos.y = self.eyeheight + (amplitude * Math:Sin(2 * 3.14 * frequency * (Time:GetCurrent() * .1) + phase)) end Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted January 9, 2014 Share Posted January 9, 2014 The le2 community project with the zombies also had head bobbing. perhaps you can find the solution in it there. Quote Link to comment Share on other sites More sharing options...
Tim Shea Posted January 10, 2014 Share Posted January 10, 2014 Because Time:GetCurrent() could be arbitrarily large, it is totally obliterating your phase parameter whenever you start. You need to use a time delta instead. Also, it seems like your frequency parameter is in radians, which doesn't make sense. Quote Link to comment Share on other sites More sharing options...
Tim Shea Posted January 10, 2014 Share Posted January 10, 2014 Also, as described in this question (http://gamedev.stackexchange.com/questions/46150/swaying-camera-when-walking) a better model for head bob is a cycloid. So you could use, for example: dt = Time:GetCurrent() - startTime bob = amplitude * abs(cos(dt * frequency)) y = height + bob Edit: Sorry, it just occurred to me that this was wrong. You want the delta from the time when the player started walking, so instead of previousTime, startTime, and only set it when they first press the key. Quote Link to comment Share on other sites More sharing options...
Rick Posted January 10, 2014 Author Share Posted January 10, 2014 Thanks, I'll give this a try. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.