on 17-05-2012 12:26 AM
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.
Solved! Go to Solution.
17-05-2012 01:46 AM - edited 17-05-2012 01:48 AM
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!
on 17-05-2012 02:50 AM
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.
17-05-2012 05:39 PM - edited 17-05-2012 05:45 PM
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)
on 17-05-2012 07:00 PM
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.
on 19-05-2012 06:43 PM
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
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を一度ログアウトし、再度ログインしてください。


Website ©2013 Sony Computer Entertainment Europe
All content, game titles, trade names and/or trade dress, trademarks, artwork and associated imagery are trademarks and/or copyright material of their respective owners. All rights reserved. [more info]
%%http://community.eu.playstation.com/t5/Announcements/Beta-Trial-Information/td-p/11386362
best_shooter.png%%http://community.eu.playstation.com/t5/Announcements/Introducing-Best-of-PlayStation/td-p/13741979
best_driver.png%%http://community.eu.playstation.com/t5/Announcements/Introducing-Best-of-PlayStation/td-p/13741979
best_performer.png%%http://community.eu.playstation.com/t5/Announcements/Introducing-Best-of-PlayStation/td-p/13741979
best_footballer.png%%http://community.eu.playstation.com/t5/Announcements/Introducing-Best-of-PlayStation/td-p/13741979
best_fighter.png%%http://community.eu.playstation.com/t5/Announcements/Introducing-Best-of-PlayStation/td-p/13741979
best_creator.png%%http://community.eu.playstation.com/t5/Announcements/Introducing-Best-of-PlayStation/td-p/13741979
best_action_player.png%%http://community.eu.playstation.com/t5/Announcements/Introducing-Best-of-PlayStation/td-p/13741979
dev2.png%%http://community.eu.playstation.com/t5/Website-and-Forum-Help-Feedback/Producer-and-Developer-Ranks/td-p/18407352
trophy.gif%%http://community.eu.playstation.com/t5/Website-and-Forum-Help-Feedback/The-Community-Awards-FAQ/td-p/18407096
PSlogoSM.png%%http://community.eu.playstation.com/t5/Website-and-Forum-Help-Feedback/Online-Support-Coordinator-rank/td-p/18414870