XNA Creators Club Online
Page 1 of 1 (9 items)
Sort Posts: Previous Next

[Solved] Platformer Starter Kit - Climbing

Last post 10/1/2009 7:42 AM by Lewis Cowles. 8 replies.
  • 4/24/2009 2:06 AM

    [Solved] Platformer Starter Kit - Climbing

    Hey there!  I'm tweaking the platformer starter kit a little bit and I'm a lil' stuck here.  I've set it up so there are some ladders in the game, these are simply drawn on, not through tiles (because the character can move them).  But I'm stuck as to getting the character to actually climb up them.

    Here is the code I'm using:

                if (keyboardState.IsKeyDown(Keys.P)) 
                { 
                    if (Level.Player.BoundingRectangle.Intersects(ladderRec) 
                        | Level.Player.BoundingRectangle.Intersects(ladderRec2) 
                        | Level.Player.BoundingRectangle.Intersects(ladderRec3) 
                        | Level.Player.BoundingRectangle.Intersects(ladderRec4)) 
                    { 
                        position.Y -= 10; 
                    } 
                } 

    The ladderRecs are placed above each other, and the character only travels 55 pixels for some reason.  I can't quite work out why.... anyone have any ideas?  Thanks for the help!

    I got this to work with a slight modification of the above code.  I just increased the amount.
  • 4/26/2009 12:12 PM In reply to

    Re: Platformer Starter Kit - Climbing

    I also have tried adding in this line to the apply physics:

    velocity.Y += movementY * MoveAcceleration * elapsed; 


    And then when the character would climb the ladder velocty.Y would be +5.  The character just zoomed up in the air forever though.
  • 4/26/2009 9:34 PM In reply to

    Re: Platformer Starter Kit - Climbing

    What was the solution??
  • 4/27/2009 12:31 AM In reply to

    Re: Platformer Starter Kit - Climbing

    Turkish:
    The character just zoomed up in the air forever though.

    Because you didn't trap when he stopped climbing most likely.
    Jim Perry - Microsoft XNA MVP
    If people spent a minute searching the forums and reading the FAQs before posting I'd be out of a job.
      Got some XNA Game Studio/XNA Framework development info to share with the community? Put it on the XNA Wiki.
        Please mark posts as Answers or Good Feedback when appropriate.
  • 4/27/2009 9:54 AM In reply to

    Re: Platformer Starter Kit - Climbing

    I'm still learning xna, and i am also trying to get the player to climb a ladder but I cant seem to get it to work, i have tried a couple of things but it doesn't work, how dit you do it???
  • 4/28/2009 5:32 PM In reply to

    Re: Platformer Starter Kit - Climbing

    You might want to provide more details about what you tried and what went wrong if you expect any help. Here it sounds as if you just want a code sample you can copy without bothering to understand...
  • 4/29/2009 8:59 AM In reply to

    Re: Platformer Starter Kit - Climbing

    I solved it already, I changed my code so now its a tile instead of a image, but thanks anyway.
  • 7/30/2009 12:33 AM In reply to

    Re: Platformer Starter Kit - Climbing

    I dont really think this thing should be marked as solved just yet, the guy that said:
    shadowsr:
    I solved it already, I changed my code so now its a tile instead of a image, but thanks anyway.


    he may have solved it, but the main person who started the post Turkish probably didnt solve it. also on a side note, shadowsr, o you mean you made it fully functional? if you did, maybe you could share a little help or maybe a solution?? =D
  • 10/1/2009 7:42 AM In reply to

    Re: Platformer Starter Kit - Climbing

    All gameObjects should have a float declared named gravity and when climbing it is set to 0.0f, otherwise it is set to 0.5f or something similar

    put this in your games update method before doing movement


    player.gravityOn(); // could be player.gravity = true; 
    if(ladderbox.Intersects(playerbox)) 
        player.gravityOff(); // could be player.gravity = false; 

    another way to use ladders is to make player move up by gravity*2 when climbing requiring a climbing variable usually set to false

    you can use the same code for a jetpack btw just think a ladder code above is linear speed, a jetpack requires velocity so for a jetpack you would have a maximum velocity (proba]bly in a Vector2 or Point) and keep adding to the .Y until velocity.Y >= maxVelocity.Y, then at the end

    if (velocity.Y > maxVelocity.Y){ velocity.Y = maxVelocity.Y; }

    also a jetpack requires no collision however checking the player does not collide with the walls is a good idea, I made a few jetpack games where fi the players velocity was too high when they hit a wall they lost health and lives! just some extra food for thought

Page 1 of 1 (9 items) Previous Next