X/Y/Z Collision
Blitz3D Forums/Blitz3D Beginners Area/X/Y/Z Collision
| ||
Hi, another one from me! I have a jump code that lets my player jump when its in collision with the world, to prevent him jumping, without his feet touching anything. Here is the code! If KeyHit(57) If EntityCollided(player,world_col) While Player_velocityY =< 2 Player_velocityY = Player_velocityY + Gravity Wend EndIf EndIf It works perfect... so far. I was thinking of adding a pivot with a collision radius as a child of the player, to detect if the players feet area is touching the ground. At this point, pressing jump and standing against the wall, makes the player fly up. Funny as it is, that's not what I need :P Before I make the child radius, is there a way to detect if a certain part/location of a collision radius is colliding? Thanks!! |
| ||
you could always load the walls in as a seprate entity. |
| ||
That is an option. I have thought of that as well. I'd still like to know how this is done, cause I have a small team who will be working on the maps and models, so I want to do it properly so it will be as simple as possible for them. thanks |
| ||
Check the collision normals. That will tell you what angle the collision happened. |
| ||
I guess your last reply in the next link is covering this. How could have I missed that thread? :-\ http://www.blitzbasic.com/Community/posts.php?topic=79122#888485 Anyway, gonna try to implement it! Thanks! |
| ||
What i do, is a linepick straight down from the characters position. Basically, it will return how close the ground is and if there is any ground below the characters. Slightly, ever so slighly slower than using normal collisions, but i find it more useful. |
| ||
Or you could use the existing collision information to find the average collision normal in the Y direction. If it's > 0 the normal points up and your standing on something. Like so :If KeyHit(57) If EntityCollided(player,world_col) If CollNY( player ) > 0 While Player_velocityY =< 2 Player_velocityY = Player_velocityY + Gravity Wend EndIf EndIf EndIf Function CollNY#( Entity ) Ny# = 0 cc = CountCollisions( Entity ) For c = 1 To cc Ny# = Ny# + CollisionNY( Entity , c ) Next Return ( Ny / cc ) End Function Even then, your jumping code doesn't look right. You want to be adding an acceleration ( greater than gravity ) to the velocity in the upward direction if jump is pressed and you are on the ground. Also, apply gravity whenever you are not on the ground. You'd need to play with the gravity and jumpacceleration variables .. Const Gravity# = 9.81 Const JumpAcceleration# = 25.0 . . . . OnGround = ( CollNY( player ) > 0 ) If OnGround If KeyHit(57) Player_velocityY = Player_velocityY + JumpAcceleration EndIf Else Player_velocityY = Player_velocityY - Gravity EndIf Stevie |
| ||
Thanks a lot, Stevie! |