Jump to content

Math:Sin()


Rick
 Share

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...