gravity
Blitz3D Forums/Blitz3D Beginners Area/gravity
| ||
Hi, I am trying to write a function that creates a simulated gravity on an object. I want this function to only apply IF the player is not colliding with the terrain. I can not seem to find the right command to check the players Y and the terrains Y and see if there is a collision. I assume that you could just check to see if they are colliding, and if not, then apply gravity..but I cannot figure out how. Any Suggestions? |
| ||
the way i would do it is to always apply gravity to the object in question. just make sure that you use collision response 3. well that is unless you want the object to slide down slopes. For player characters i wouldn't recommend that, unless the slopes are quite steep. :D |
| ||
If I have understood correctly, Providing the collisions are set up correctly (assigning EntityTypes to the player entity and the terrain, you can have gravity acting on the player constantly and it wont 'fall through' the terrain. However EntityY#(player_entity_name) and TerrainY#(terrain_name) are the commands you're looking for. |
| ||
thanks malice. That is correct. I ended up using those two togeter in this function, and it works quite well. It only applies gravity if the player is greater than the entity radius ( i would imagine this speeds things up since gravity is not constantly applied). Here is the function I used: Function applyGravity (ent, ent2) If Abs(EntityY# (ent) - EntityY#(ent2)) > camHeight# TranslateEntity ent, 0, gravity#, 0 EndIf End Function |
| ||
Also, I just realized after posting this, that the camHeight# is not portable, the function should have been: Function applyGravity (ent, ent2, radius#) If Abs(EntityY# (ent) - EntityY#(ent2)) > radius# TranslateEntity ent, 0, gravity#, 0 EndIf End Function |