Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tap for small jump? #67

Open
digiwombat opened this issue May 11, 2017 · 1 comment
Open

Tap for small jump? #67

digiwombat opened this issue May 11, 2017 · 1 comment

Comments

@digiwombat
Copy link

Currently, you can only full jump or hold for really awkward extra height (since holding just turns off gravity, I believe).

I'd like to be able to tap for a small jump and hold for the full height, rather than get EXTRA height (which comes on awkwardly if you set a small minimum jump (0.1f) and a larger full height (4f).

Basically, look at Metroid or Castlevania and you can tap for a small jump rather than quick tap giving you full height.

@digiwombat
Copy link
Author

digiwombat commented May 12, 2017

Alright, I implemented this roughly for now in my own instance. I'll explain it here for people looking to do the same thing.

Firstly add two variables to PlayerMotor2D.cs:

public float minJumpHeight = 0.5f;
public bool endJumpEarly = false;

Then add this to MoveMotor() (also in PlayerMotor2D.cs)

if (endJumpEarly && motorState != MotorState.OnGround)
{
	if (_velocity.y > CalculateSpeedNeeded(minJumpHeight))
	{
		_velocity.y = CalculateSpeedNeeded(minJumpHeight);
	}
}

Finally! In PlayerController2D.cs (or your local equivalent) add the following to Update():

if(_motor.motorState != PlatformerMotor2D.MotorState.Jumping)
{
	_motor.endJumpEarly = false;
}

if (Input.GetAxis(PC2D.Input.VERTICAL) > -0.5f && Input.GetButtonDown("Jump"))
{
    _motor.Jump();
    _motor.DisableRestrictedArea();
}

if(Input.GetButtonUp("Jump"))
{
    _motor.endJumpEarly = true;
}

That'll do it. There's probably a smarter way to set endJumpEarly, but for now it'll do for double jumps and the like. The onGround check might honestly be redundant, but I figure passing over the second, more complicated if() statement is probably for the best.

EDIT (13 May): Changed the endJumpEarly thing to what I originally had it as. Might interfere with double jumps. Maybe. Somehow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant