detecting if a player has "stepped" ?
Blitz3D Forums/Blitz3D Programming/detecting if a player has "stepped" ?
| ||
how would i detect if the foot of the player has hit the ground? |
| ||
foot_bone=findchild charMesh,"leftFoot" collPivot=createPivot(foot_bone) Entitytype collPivot,colltype EntityRadius collPivot,radius# check for collPivot blitz collision with the ground Surface (using CollisionSurface etc..) btw I don't think it's a wise thing.. |
| ||
I'm gonna take a wild guess (as well as noting your other post about the animation sequences/time) that this is perhaps due to wanting to synchronise footstep sounds with the placement of the foot(or feet) on the ground? It would make sense that you have some frame limiting or timing tehnique to ensure a single 'walk' sequence will always take the same time. All you need to do, is sync the playing of two footsteps one with the duration/2 and another at the duration. This also assuems you cancel the animation (switch to, say, 'idle') if the player stops walking halfway through. It's much more efficient to have the sound played every x seconds than to constantly check the positions and collisions. |
| ||
What i would do, is check the animtime command (which is actually the current frame) Visually, check which frames the players feet hit the ground, and play the sound. |
| ||
yes, i wanna synchro the footsteps when the feet touch the ground. so far, here is what i have: |
| ||
You could attach Pivots to the feet bones using FindChild(entity,"Left_Foot") then put the collisions on the pivot. |
| ||
i like that idea much better |
| ||
..collision for footsteps is very wrong idea..checking specific frame is much more better and faster, as Ross already mentioned.. |
| ||
i dont care if its a LITTLE slow. sheesh. im not trying to make a state-of-the-art game. i only care if its fast enough to run on windows 98 & up |
| ||
The operating system is mostly irrelevant. Checking through the ENTIRE collision table every loop for just the footsteps is gonna be intensive, especially since you haven't even exited the loop after a positive result. It would probably make more sene to combiine the collision event checks in the loop so you don't need to make multiple checks. If you're not bothered about the efficiency of your code, then does this mean we wont see posts about "low framerates" or "why is my game so slow?" Efficiency of the codeis even more crucial if you're not using state-of-the-art techniques to minimise overheads and manage resources. |
| ||
i never said that. i said i simply want it to run not VERY fast, but fast enough for a player to play around 40-60 fps on a windows 98 or higher |
| ||
I would advise against NOT checking for positive collision between a foot and the ground. Why? Because unless you have some switch or flag to flip, the collision may trigger say 15 or 20 frames in a row, creating a machine-gun footstep effect. What about when the player is standing still? 2 positive collisions between both feet and the ground = 2 constant machine-gunning sound effects. To make that work you'll have to only check for collisions until a collision is detected, then say don't check again until x frames of walk animation again... or something... anyway it'll get way complicated. Ross C's idea is much, much simpler than the collision method. However, you will still have to have a switch or flag to not play the sound while the player is standing still. Alternatively, I guess you would only need to check it while the player is animating in the walk\run cycle. |
| ||
If it were me i would just record which frames in the animation a players foot touches the ground and play the footstep at that moment. |
| ||
ive decided im just going to attach very small invisible spheres to the feet, and detect if they collide |
| ||
Sounds good to me. There's always more than one way to do everything :) |
| ||
Indeed ^^ |
| ||
This will trigger the footstep to fire, but I'll tell you right now that it may trigger the sound for many more than 1 single frame. The foot will more than likely be colliding with the ground, or terrain, or whatever, for say 5 or 8 frames before being lifted again, and that will trigger the footstep sound 5 or 8 frames in a row. What that will do is turn your step sound into RATATATATATATSTEP. You'll have to code the sound to play only once every animation cycle. |
| ||
Don't worry, if that happens then you'll know why more threads are created by Rez about "repeated sound glitch". |
| ||
..thats why I have suggested simple frame check..works like a charm and no issues such as sound repetition.. |
| ||
I agree with Naughty Alien. |
| ||
ok, how would u do a frame check? frame = frame + 1 or something? idk, ive never seen this type of code |
| ||
something like thisif frame_playing_from_my_current_sequence = one_of_the_Stored_frames_for_current_sequence emitsound(my_footstep_sound) end if something like this... |
| ||
animtime command gives you the current frame. |
| ||
ok cool |