what is the best way to add gravity
Blitz3D Forums/Blitz3D Beginners Area/what is the best way to add gravity
| ||
yes i know i have been posting alot but i'm just starting and i can't figure out some of these things but anyway what is the best way for gravity u could give me an example or if there is a tutorial i don't know about that will work too, woops wrong forum |
| ||
simple gravity:TranslateEntity camera, 0, -1, 0 |
| ||
Have a variable called gravity. when the player isn't touching the ground, decrease this variable by 0.1 everyloop, untill he is touching. Make sure the variable doesn't go below -70 though.gravity# = 0 while not keyhit(1) if player not touching ground then; pseudo code gravity = gravity - 0.1 if gravity <-70 then gravity = -70 end if else gravity = 0 end if moveentity camera,0,sin(gravity),0 Wend Some rough code. Basically use Sin to create simple acceleration using the sin wave. :o) Works pretty well. |
| ||
Im having troubles getting it to work, how are you testing to see if your player has collided with the level?? |
| ||
This is somethign that I wrote ages ago as a tutorial that might help |
| ||
Gravity causes accelleration. To properly model accelleration, you need to keep track of the velocity of your entities. To keep track of additional information for an entity, use a TYPE:Const GRAVITY# = 0.02 Type physical_body Field entity ; each physical_body represents one entity Field vx#, vy#, vz# ; keep track of velocity End Type ; here's a simple constructor to make it easier to create objects Function create_physical_body.physical_body(entity) this.physical_body = New physical_body this\entity = entity Return this End Function ; don't work with entities directly: ;player = createcube() ;positionentity(player, 1, 2, 3) ; instead, create objects to store the entities: player.physical_body = create_physical_body( CreateCube() ) PositionEntity(player\entity, 1, 2, 3) ; game loop While Not(KeyHit(1)) ; update all physical_bodies For pb.physical_body = Each physical_body pb\vy = pb\vy + GRAVITY ; add gravity TranslateEntity(pb\entity, pb\vx, pb\vy, pb\vz) ; move entity Next ; update graphics RenderWorld Flip Wend Don't call TranslateEntity() directly anymore. Instead, modify the velocity of your physical_bodies and let the physics updating code in the loop move the entity for you. P.S. Yes, there is a way to find the physical_body object that represents an entity, given only the entity (e.g. from a Pick.) To do so, store the object's Handle() in the entity's EntityName. |
| ||
A sidenote: you maybe need to add a pivot right between the feet of the characater to check if he collided with the ground. Checking for ground contact with the entire mesh or the shoes is not a good idea since it/they can touch walls as well, so you would allow him to climb up walls as if he was standing on the ground. Using a pivot between the feet, with an EntityRadius that is big enough to detect the ground and ONLY the ground can fix this. An other solution is to use a linepick against the ground. |
| ||
also |
| ||
'also' what? If you're making a point or asking a question then you might want to do it less idiotically. |
| ||
Hmmm, maybe Skydude's spamtastic. |