Rick Posted January 9, 2014 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
AggrorJorn Posted January 9, 2014 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
Tim Shea Posted January 10, 2014 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
Tim Shea Posted January 10, 2014 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
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.