- Home /
Charge Jump Help!!!
Im using the original fps controller script, first question, should i use that?
Second question, how would i implement a "Charge Jump" Into that script? here is a script thanks to static_cast.
private float jumpStrength = 0f;
void OnGUI()
{
if(GUI.Button(YOURBUTTONSTUFFHERE))
{
jumpStrength += Time.deltaTime;
if(jumpStrength >= 200)
Jump();
}
else
{
if(jumpStrength > 0)
Jump();
}
}
void Jump()
{
jumpStrength = 0f;
//JUMP CODE HERE
}
Just to clarify, i dont want a button on screen, i just want to be able to charge my space bar.
Answer by BackslashOllie · Nov 28, 2016 at 08:31 AM
Hi, I am slightly guessing what you mean by "charge my space bar" but please see below example. This code will increment jumpStrength
whilst the space bar is held down and will call the Jump()
method when the space bar is released.
[SerializeField]
private float jumpStrength = 0f;
private float multiplier = 20f;
// Update is called once per frame
void Update()
{
if (Input.GetKey(KeyCode.Space))
{
jumpStrength += (Time.deltaTime * multiplier);
}
else if (Input.GetKeyUp(KeyCode.Space))
{
Jump();
}
}
void Jump()
{
Debug.Log(jumpStrength);
jumpStrength = 0f;
}
Would there be a way to implement "$$anonymous$$ax Jump". Like where the jumpStrength cant go up anymore and executes the jump code?
Your answer
Follow this Question
Related Questions
how to make 2d character jump? 0 Answers
Help with Character Controller Platform Physics 0 Answers
,How to disable autojumping when holding spacebar? 4 Answers
how to keep mid air velocity using character controller? 0 Answers
Jumping not always work 2 Answers