![]() |
|
![]() |
![]() |
![]() | Donate | ![]() |
![]() |
![]() |
Ouvrir sur le forum | Recherche | Messages du jour | Marquer les forums comme lus |
Aide au développement Aide sur l'utilisation d'OSLib |
Publicité |
![]() |
|
Outils de la discussion | Modes d'affichage |
![]() |
#1 |
Membre
Date d'inscription: 22/01/2009
Messages: 17
|
![]() Hello I'm trying to create physics for my platformer (jumping and gravity). But when I press (X) the player just swaps to the vertical height. So lets say when I press X the player's Y cordinate will decrease by 64 so it will jump into the air 64 pixels. But it does it all at once, I want it to slowly assend into the air 1 pixel at a time like in a real platformer. So basicly I wanted the player to continously assend untill it assended 64 pixels. I've tried implimenting it like this:
Code:
{......} void newGame() { int RLimit = 250; int LLimit = 50; extern int canJump; oslCls(); // Draw map and player oslDrawMap(mapCollision1); oslDrawImage(player); // Active gravity if(!collisionMgr(mapCollision1,player,0,0,0,1) && canJump == !1) { player->y += 1; } else if(collisionMgr(mapCollision1,player,0,0,0,1)) { canJump = 1; } else if(!collisionMgr(mapCollision1,player,0,0,0,1)) { canJump = 0; } // Character movement with camera and collision detection if(osl_keys->held.right && !collisionMgr(mapCollision1,player,0,1,0,0)) { if (player->x >= RLimit) { map1->scrollX += 1; mapCollision1->scrollX += 1; } else { player->x += 1; } } if(osl_keys->held.left && !collisionMgr(mapCollision1,player,1,0,0,0)) { if (player->x <= LLimit) { map1->scrollX -= 1; mapCollision1->scrollX -= 1; } else { player->x -= 1; } } if(osl_keys->pressed.cross && !collisionMgr(mapCollision1,player,0,0,1,0)) { if(canJump == 1) { player->y -= 64; canJump = 0; } } } {......} ![]() I asked this question on another forum and they directed me here http://www.tonypa.pri.ee/tbw/tut07.html I understand it a bit but some parts are complex ![]() ![]() |
![]() |
![]() |
Publicité |
![]() |
#2 |
Membre confirmé
|
![]() jumping is not something very difficult to add in a game
![]() first, you have to include gravity. It will increase your Y speed, simulating a falling object ('sy' is your character Y speed) Code PHP:
when you're on the ground, you can jump ! Code PHP:
- Y speed will start being negative : the character will "fly" - each loop increases this speed : the character reduces its jump - at some point, speed reaches 0 : character is at the highest point of its jump - then it falls basically, to make a character jumping, you just have to input a negative Y speed (whatever value does the trick. A higher negative one makes a higher jump) to your character and the gravity will do the rest ![]() |
![]() |
![]() |
![]() |
#3 |
Membre
Date d'inscription: 22/01/2009
Messages: 17
|
![]() Thanks so I tried it like this:
Code PHP:
but it would get stuck in the tile when he'd come back down and if he is jumping and there is another tile above the player it would get stuck. I wasn't sure what would happen if my player comes back down so I set the speed to zero if thats not right please tell me. EDIT: I think my collision system doesn't work well. What would be a good method of collision in this situation? I used this method of collision from tutorial 10: Code PHP:
EDIT: Alright, I think I figured it out how I can get the player out if it falls into the tile: while(player-y is bellow the title) { player--; } As you can see I'm not completly sure about the while part I mean how would I get the current level of the tile using the collision system from tutorial 10? Dernière modification par pspmasterpro ; 17/03/2009 à 17h23. Motif: Help |
![]() |
![]() |
![]() |
#4 |
Membre
Date d'inscription: 22/01/2009
Messages: 17
|
![]() *bump
|
![]() |
![]() |
![]() |
Liens sociaux |
Publicité |
Utilisateurs regardant la discussion actuelle : 1 (0 membre(s) et 1 invité(s)) | |
Outils de la discussion | |
Modes d'affichage | |
|
|