Gravity woes
Blitz3D Forums/Blitz3D Beginners Area/Gravity woes
| ||
Hello. I am having difficulties with my character's movement/collision with the ground, and it's partly to do with the gravity. I'm currently working on having my character walk along the ground in a 3D environment and still keeping ground level. The 3D environment is a .x file with an irregular surface, and some parts include raised pavements/sidewalks, so there are a few different types of elevated ground to tackle. Though the pavements do rise up vertically they are not terribly high - they come up to approximately the top of the player model's shoe. However some slopes are approaching something akin to a 25 degree angle. Here is the code which handles this (it's very simple, possibly part of the problem): ------------------------------------------------------------ ;Collisions Const TYPE_PLAYER=1,TYPE_CAMERA=2,TYPE_SCENERY=3 ; Player-to-scenery Collisions TYPE_PLAYER,TYPE_SCENERY,2,3 gravity#=EntityY(hero\entity) y_vel#=(gravity-hero\y) hero\y=gravity y_vel =-.2 TranslateEntity hero\entity,0,y_vel,0 ------------------------------------------------------------ The first bit is outside of any looping bits of code. The third part is inside a Function "updatePlayer", and the middle part is in a "Repeat...Forever" loop. Now it's working okay, but there's a couple of big problems I'm having so far: namely some slopes are pretty hard to move up, and the kerb on the side of the street is nearly impossible to traverse unless you run at it at certain angles. I'm guessing it's to do with the "gravity" constantly pulling it down, but I can't think of any other manner with which to keep the player on ground level yet still allow them smooth movement over these parts. Any suggestions? Ideas? I'd be very grateful. |
| ||
I am extremly confused by your code. try this: const gravity#=-.2 ;Collisions Const TYPE_PLAYER=1,TYPE_CAMERA=2,TYPE_SCENERY=3 ; Player-to-scenery Collisions TYPE_PLAYER,TYPE_SCENERY,2,3 hero\y_vel#=hero\y_vel#+gravity# hero\y=hero\y+hero\y_vel translateentity hero\entity,0,hero\y_vel,0 note: this might be wrong as I did it in the browser :-/ also, it assumes that you have a y_vel field in type hero. |
| ||
The answer is simple - sliding collisions. The sliding collisions means that if your walking speed isnt great enough, certain slopes become an uphill struggle (literally). Either turn them off or, better still, alter the speed / gravity settings until you get the desired effect. You may want to add some kind of 'smart gravity' routine which checks if the player is on a slope, but I suggest something simpler unless you're a pro. |
| ||
Okay. Thanks for your help everyone. |