- Home /
I need help with fixing my "up special" mechanic.
Recently i learnt how to make a double jump mechanic, and i wanted to challenge myself and create a up-special one. But for some weird reason i can do 2 up-specials after each other which is quite annoying.
Important variables public float jumpForce;
public bool isGrounded;
public Transform groundCheck;
private int extraJumps;
public int extraJumpValue = 1;
private bool LookUp;
private int AmountOfUpSpecial;
public int AmountOfUpSpecialValue;
Void start function
void start()
{
extraJumpValue = 1;
extraJumps = extraJumpValue;
AmountOfUpSpecialValue = 1;
AmountOfUpSpecial = AmountOfUpSpecialValue;
rb = GetComponent<Rigidbody2D>();
}
My fixed Update function(dont think its that important)
void FixedUpdate()
{
//Player 1 movement
isGrounded = Physics2D.OverlapCircle(groundCheck.position, checkRadius, whatIsGround);
if (P1 == true)
{
if (Input.GetKey("d"))
{
if(isGrounded == false)
{
moveInput = 1;
rb.velocity = new Vector2(moveInput * speed / 1.4f, rb.velocity.y);
}
else if (isGrounded == true)
{
moveInput = 1;
rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);
}
}
else
{
rb.velocity = new Vector2(0, rb.velocity.y);
}
if (Input.GetKey("a"))
{
if(isGrounded == false)
{
moveInput = -1;
rb.velocity = new Vector2(moveInput * speed / 1.4f, rb.velocity.y);
}
else if (isGrounded == true)
{
moveInput = -1;
rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);
}
}
}
//Player 2 movemt
if (P1 == false)
{
if (Input.GetKey("right"))
{
if(isGrounded == false)
{
moveInput = 1;
rb.velocity = new Vector2(moveInput * speed / 1.4f, rb.velocity.y);
}
else if (isGrounded == true)
{
moveInput = 1;
rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);
}
}
else
{
rb.velocity = new Vector2(0, rb.velocity.y);
}
if (Input.GetKey("left"))
{
if(isGrounded == false)
{
moveInput = -1;
rb.velocity = new Vector2(moveInput * speed / 1.4f, rb.velocity.y);
}
else if (isGrounded == true)
{
moveInput = -1;
rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);
}
}
}
//Flip function
if (facingRight == false && moveInput > 0)
{
Flip();
}
else if (facingRight == true && moveInput < 0)
{
Flip();
}
}
My Update function + my ground == true function.
void Update()
{
//Moves
//Up special
if(P1 == true)
{
if(Input.GetKey("w"))
{
LookUp = true;
}
else
{
LookUp = false;
}
}
if (P1 == false)
{
if(Input.GetKey("up"))
{
LookUp = true;
}
else
{
LookUp = false;
}
}
//Jumping
if (P1 == true)
{
if(Input.GetKeyDown(KeyCode.Space))
{
if(LookUp == true && AmountOfUpSpecial > 0)
{
rb.velocity = Vector2.up * jumpForce * 2;
AmountOfUpSpecial = 0;
extraJumps = 0;
}
else if (LookUp == false && extraJumps > 0)
{
rb.velocity = Vector2.up * jumpForce;
extraJumps =- 1;
}
else
{
print("You cant jump!");
}
}
}
else if (P1 == false)
{
if(Input.GetKeyDown(KeyCode.I))
{
if(LookUp == true && AmountOfUpSpecial > 0)
{
rb.velocity = Vector2.up * jumpForce * 2;
AmountOfUpSpecial -= 1;
}
else if (LookUp == false && extraJumps > 0)
{
rb.velocity = Vector2.up * jumpForce;
extraJumps--;
}
}
}
if(isGrounded == true)
{
extraJumps = extraJumpValue;
AmountOfUpSpecial = AmountOfUpSpecialValue;
}
}
If you need any more info i can provide, and yes i am new to game dev.
Answer by logicandchaos · Feb 06, 2021 at 02:11 PM
line 44 looks like it should be extraJumps -= 1; instead of extraJumps =- 1;
Do you only get one extra extra jump? like can you special jump > than 2 times? if so you might have to change a to a =
Your answer
Follow this Question
Related Questions
Raycast2D not working 1 Answer
Long press for charged Jump 1 Answer
Another Slow Fall Problem... 2 Answers
[Solved] Having trouble with 2D Character Jump using Bolt 0 Answers
change multiple jump to single jump 1 Answer