EmericaSkater, on 06 May 2011 - 10:03 AM, said:
For at least a few months now, I've been wanting to create a noticeable head-bobbing effect that takes place whenever the player walks, like you'd see in Doom and a few other older FPS. Now mind you, I've been assuming this entire time that DN3D had no such effect, because I'd never noticed any significant change in the camera's position if I was just walking/running. When I was messing around with it this morning, though, I put the cameraz var into a digitalnumber command just to see what its value was at, and low and behold, the number changed as I was walking. So there's clearly a bobbing effect going on, and I just want it to be more pronounced. Considering that, my two questions are - -
1) Is there any con-access to the value that's being added/subtracted to the cameraz variable when the player moves?
and if not, then
2) can I get any advice on how to start manipulating that variable in tandem with the player's movement? I've altered the cameraz variable easily enough when I was setting it to a fixed number, but trying to make it move up and down in a fluid pattern as the player moves is probably going to be way more challenging.
Interesting problem. Here's what I would do (and I might do it myself if I have time later today). First, in one of the display events (you could use EVENT_DISPLAYROOMS), set the cameraz to the player head height (getplayer[screenpeek].posz cameraz). This will set the height to a neutral position before you manipulate it, thereby negating whatever hardcoded z movement is going on. Next, use a sin function to make the camera move up and down when the player is on the ground and walking/running. Use the player's velocity (determined by posxv and posyv in the player struct) to determine the length of the wave (higher velocity means shorter waves). You also need to factor the passage of time in there somewhere, comparing player_par from the start of movement to the current time (I know that's vague, but it would be easier if I were looking at actual code). Shift the result some bits to the right or left as appropriate (probably to the right, since the result of the sin function will give you a big number) and add the result to cameraz. If your mod uses footstep sounds, make them occur when cameraz is at the lowest point.