Walking + Gravity + Animation

Blitz3D Forums/Blitz3D Programming/Walking + Gravity + Animation

Whats My Face(Posted 2010) [#1]
Hey I have found that it is difficult to get my walking code right. The problem is that I can't have gravity on all the time or the character has a hard time walking up steep hills. But if I leave it off then the character temporary leaves the ground and it takes a frame or so to get him back on making the animation look bad and the camera a bit shaky. Has anyone found a good way to turn gravity completely off while the character is still on the ground but not have the character leave the ground for a frame or so at a time? Some code would be greatly appreciated.


Serpent(Posted 2010) [#2]
I have had similar problems to this in a simple tanks game i tried to create. If a tank moved along the side of a hill in the terrain, it would often fall through and end up underneath the terrain constantly falling. I got around this through two things: first of all, making my value for gravity low - btw my 'gravity' was just every frame moving the tank down a certain amount, no acceleration whatsoever. Secondly, the main part of my solution lay with the rotation of the tank. The tank rotates with the landscape, so effectively it moves up along the surface of a hill rather than trying to move through it because it tilts up when reaching the higher ground.

This doesn't apply very well to your situation. However, I think you can get Collision Normals. If you call CollisionNY#(entity,index) after each collision in each frame, you can get how a multiplier for how high up your character needs to move in order to match the slope of the hill. With this, you could move your character up the correct amount to make it look like it's walking up the side of the hill rather than into it. This should also prevent your character from walking 'through' the hill (which is the main problem anyway). I'll see if I can get some example code working...


_PJ_(Posted 2010) [#3]
CollisionNY#(entity,index)

Yeah this should help.

Also, bear in mind, that however your gravity is implemented, walking along a slope, the gravity should only impede movement downwards, so depending on the incline, Cos(angle) will give the appropriate effect of gravity, i.e. walking perpendicular to the direction of gravity (i.e. flat ground) will be affected by gravity * 0 = 0
However, movement parallel to gravity, such as upwards, will be 100% affected.


Guy Fawkes(Posted 2010) [#4]
can someone show an example of this with a computer generated hill OR a mesh? I too would like to see how this works.


nrasool(Posted 2010) [#5]
Doesn't the Castle demo show you this? It one of the samples in Blitz3d


Whats My Face(Posted 2010) [#6]
Using CollisionNY# and aligntovector has been really helpful, thanks. However, my character has become Spider Man. I was thinking about figuring in the slope into the gravity like Malice said unless anybody else has a better method?


Guy Fawkes(Posted 2010) [#7]
reset ur vector after using it. maybe that would work?


Ross C(Posted 2010) [#8]
Check the value of NY#, before aligning. This will be the slope gradient essentially. Have a play about with it.


RifRaf(Posted 2010) [#9]
Similar to how ive done it. I have two gravity values applied, one value is always applied and the second stronger value is applied when there are no collisions ( in the air ), and I dont align to the ground if the collisionNY is not within tolerance.

This allows steeper slopes to slow the movement some but not drastically wich works for my tank game. I guess if you were planning this for humanoid movement you wouldnt want any slowing at all. In wich case the CollisionNY angle value effecting the gravity directly would work best.


Kryzon(Posted 2010) [#10]
I was thinking about figuring in the slope into the gravity like Malice said unless anybody else has a better method

From what I remember from my tests in this subject, try only applying gravity to characters that are in movement.
The characters won't flicker, and they also won't stay a bit "on the air" when, say, travelling through a terrain or such. They also won't slide down slopes if they stop right in the middle of one.

Just make sure to use a strong enough gravity value (this will change based on the scale of your world and elements).

EDIT: In case there cliffs in your game (where the above method will need some modifications), try linepicking every other frame (for performance reasons) to see if the character is actually standing above ground. Don't use the character's hull for collisions or else he might be stuck at mid-air for touching the level with his arm, for instance.