Input

Reply

Level 1

Level 1
asdfADRIAN
Posts: 36
Registered: ‎15-05-2012
Message 1 of 6 (395 Views)
Accepted Solution

Double Jump

Im trying to implement a double jump feature, heres the following code:

 

if (AirborneTime > 0.0f )
	{
		if (PlayerInput.JumpButton())
	              Velocity += Vector2.UnitY * JumpPower;
		      //AirborneTime = 0;
	}

 However, the problem with this is that I can consecutively press the Jump button and my character will continuously flutter in mid air like a bird flapping its wing. 

How would I be able to limit this? How would I check for a double tap or even better use double jump lets say only once every 2 seconds? 

 

Come join The Freenode IRC at Channel #pss-dev!

I am merely a graphics designer who wants to program, go figure.

Please use plain text.

Re: Double Jump

[ Edited ]

I guess you can do this:

 

if (AirborneTime > 0.0f )
{
                bool dJumped;
                dJumped = false;
           
		if (PlayerInput.JumpButton() && !dJumped)
                {
	              Velocity += Vector2.UnitY * JumpPower;
		      //AirborneTime = 0;
                      dJumped = true;
                }
}

 

OR (For double jump again after two seconds)

 

Setup a Stopwatch:

 

Stopwatch watch = new Stopwatch();

 

Then you change the first lines of code to:

 

if (AirborneTime > 0.0f )
{
                bool dJumped;
                dJumped = false;
           
		if (PlayerInput.JumpButton() && !dJumped)
                {
	              Velocity += Vector2.UnitY * JumpPower;
		      watch.Start();
                      dJumped = true;
                }

                if (watch.Elapsed > TimeSpan.FromSeconds(2))
                {
                    dJumped = false;
                    watch.Stop();
                    watch.Reset();
   watch.Start();
                }
}

 

Basically, if the player is airbourne and dJumped is not equal to true (which means the player haven't double jumped) then enable double jump once and after 2 seconds enable the ability to double jump again.  I think that's it.  Tell me if it works!

 


 


Please use plain text.

Level 1

Level 1
asdfADRIAN
Posts: 36
Registered: ‎15-05-2012
Message 3 of 6 (382 Views)

Re: Double Jump

Thank you for your time to help me out! I appreciate your response. 

I have tried both solutions and unfortunately they do not work. The character is still able to double jump numerous times withotu any restrictions even with the timer.  

Come join The Freenode IRC at Channel #pss-dev!

I am merely a graphics designer who wants to program, go figure.

Please use plain text.

Member

Member
Wild--Waller
Posts: 4
Registered: ‎23-03-2012
Message 4 of 6 (365 Views)

Re: Double Jump

[ Edited ]

I'm a newbye and I'm not sure if I've realized what you need, but you could set a int n_jump = 0; so
if (PlayerInput.JumpButton() && jump <2)
{
Velocity += Vector2.UnitY * JumpPower;
//AirborneTime = 0;
n_jump++;
}

now I don't know how you calculate your jump's movement, but when you touch the ground you could reset n_jump to 0... If there aren't others floors a "if ( positiony = 0)" should go...

 

EDIT: int n_jump = 0; at the beginning of code (out the loop)

Please use plain text.

Level 1

Level 1
asdfADRIAN
Posts: 36
Registered: ‎15-05-2012
Message 5 of 6 (359 Views)

Re: Double Jump

Did not work either :\ 

 

Oh and the code you put has a typo in the following line: 

if (PlayerInput.JumpButton() && jump <2)

 it should be:

if (PlayerInput.JumpButton() && n_jump <2)

 But even with the correction it had the same result as my oriignal code and the code provided by Spykam25. ):

Come join The Freenode IRC at Channel #pss-dev!

I am merely a graphics designer who wants to program, go figure.

Please use plain text.

Member

Member
Wild--Waller
Posts: 4
Registered: ‎23-03-2012
Message 6 of 6 (335 Views)

Re: Double Jump

using System;
using System.Collections.Generic;

using Sce.Pss.Core;
using Sce.Pss.Core.Environment;
using Sce.Pss.Core.Graphics;
using Sce.Pss.Core.Input;
using Sce.Pss.Core.Imaging; // for font

using Sce.Pss.HighLevel.GameEngine2D;
using Sce.Pss.HighLevel.GameEngine2D.Base;


namespace Updating
{
	public class AppMain
	{
		public static void Main (string[] args)
		{
			Director.Initialize();
			
			int CooY = 90;
			int n_jump = 0;
			
			
			Scene scene = new Scene();
			scene.Camera.SetViewFromViewport();
   
			//Left sprite
			Texture2D texture = new Texture2D("/Application/smile.png",false);
			TextureInfo ti = new TextureInfo(texture);
			SpriteUV sprite = new SpriteUV(ti);
			
			sprite.Quad.S = new Vector2(64,64);
			sprite.Position = scene.Camera.CalcBounds().Center;
			sprite.Position = new Vector2(sprite.Position.X - 256, CooY);
			sprite.CenterSprite();
   
			sprite.Schedule( (dt) => 
			               {		
				
				// Press X (S on the keyboard) to Jump
				if(Input2.GamePad0.Cross.Press == true && n_jump < 2)
				{
					sprite.Position = new Vector2(sprite.Position.X, sprite.Position.Y + 150);
					n_jump++;
				}
				if (sprite.Position.Y > CooY)
				{
					sprite.Position = new Vector2(sprite.Position.X, sprite.Position.Y - 5);				
				}
				else
					n_jump = 0;
			});

			
			scene.AddChild(sprite);

			Director.Instance.RunWithScene(scene);
		}
	}
}

oh, sry for the mistake

starting by the solution of this tutorial I've create a simple double jump if it could help you, it seems to work to me

Please use plain text.
Announcements

Welcome to the PlayStation Mobile Developer Forums


This is a community for the discussion of technical topics with other developers and SCE engineers. Posting ideas/requests are also appreciated. Join the discussion!

PlayStation®Mobile開発者フォーラムでは世界中の開発者の皆様と一緒に、議論や情報交換が可能です。SCEも議論に参加し、皆様の開発をサポートします。アイデアやリクエストも大歓迎です。ぜひご参加ください。

PSM Developer Registration (for free) on PSM DevPortal is required to post on the forum.
Please sign out then sign in again to the forum and PSM DevPortal after you have completed the registration.

フォーラムへ投稿をするにはPSM DevPortalへの登録(無料)が必要です。
登録後はフォーラムと PSM DevPortalを一度ログアウトし、再度ログインしてください。