Jump High, but Travel Short.

This topic contains 3 replies, has 2 voices, and was last updated by  Justin at CartoonSmart 1 month ago.

  • August 25, 2016 at 3:38 pm #155034

    So I have a character, who jumps pretty high. But when he jumps and moves, he can stay in the air for an insane amount of time. You can pretty much jump and pass all the obstacles. Though, some of it can be changed by adjusting how high he can jump, but I’d like him to be able to jump high but not very far. I tried that by adjusting his jump duration, but it just turns out glitchy. Is there anyway to make him jump high, but when he moves in the air, he doesn’t go as fast/falls down faster?

    – Also I noticed there is a “soundland”. Is it possible to create “dust particles to show” when player lands on a platform?

    Thank you!

  • August 26, 2016 at 12:46 pm #155059

    Well property list wise thats really just a combination of adjusting the JumpAmount and Speed properties. Some other things do affect this, like gravity but I think its best to leave the gravity at -9.8 (the default). And come to think of it, the mass of the character too.

    But code wise you could obviously dig into the Player class and make all sorts of changes. Is that more what you’re thinking about?

    I would play around with the easy stuff first, then dig into the code if need be. Let me know!

  • August 26, 2016 at 3:37 pm #155077

    tried the combination of jump amount and speed properties, but it doesn’t seem to match my taste. Because either character would be too slow or the jump height will be too little. Gravity also make the character heavier and slower.

    Code wise, what can I do to make it work?

  • August 26, 2016 at 10:02 pm #155081

    In the Player class, here’s the main jump function…

    func jump(){
            
            if ( playerIsDead == false) {
            
            if ( isJumping == false && canJumpAgain == true) {
                
                canDoubleJumpAgain = true
                canJumpAgain = false
                isJumping = true
            
                removeAllAnimationActions()
                
                if (self.jumpAction != nil) {
                
                    self.run(jumpAction!, withKey: "Jump")
                    
                }
            
                let move:SKAction = SKAction.moveBy(x: 0, y:  CGFloat( jumpAmount ), duration: 1)
                self.run(move, withKey: "JumpMove")
                
                playSound(soundJump)
                
                
                // prevents some weirdness with super jumping via controllers
                let wait:SKAction = SKAction.wait(forDuration: 0.2)
                let jumpAgain:SKAction = SKAction.run{
                    self.canJumpAgain = true;
                    
                }
                let seq:SKAction = SKAction.sequence( [ wait, jumpAgain] )
                self.run(seq )
         
                
            }
                
            }
        }
    

    But within that, the most important part is this…

     let move:SKAction = SKAction.moveBy(x: 0, y:  CGFloat( jumpAmount ), duration: 1)
                self.run(move, withKey: "JumpMove")

    This is an SKAction that moves the player on the x and y axis. You can see that x: 0 means the action isn’t pushing at all on the x axis. Its only affecting the y axis using the jumpAmount variable, which is what the property in the .plist adjusts. And the duration is set to 1.

    So the character really shouldn’t be moving any faster than their character speed when they go up in the air. Since this has no affect on the x axis. But if you wanted to completely shut off moving on the x while jumping, you could set the currentSpeed property to 0. Of course you’ll need to reset it to the previous value when the player is done jumping. You can see there’s already an SKAction in there that waits and performs code, so you could copy that and run any block of code after the jump is initiated.

You must be logged in to reply to this topic.