I’m trying to achieve a jump much like the one they have in the game “VVVVVV”, whereas when you press space, the player flies toward the roof, and if you press again - the floor.
public float speedForce = 50f;
public Vector2 jumpVector;
public Vector2 jumpVector2;
bool isGroundedTop;
bool isGroundedBot;
public Transform grounderTop;
public Transform grounderBot;
public float radiuss;
public LayerMask groundTop;
public LayerMask groundBot;
void FixedUpdate()
{
//When the player collides, change speedforce
isGroundedTop = Physics2D.OverlapCircle(grounderTop.transform.position, radiuss);
isGroundedBot = Physics2D.OverlapCircle(grounderBot.transform.position, radiuss);
if (Input.GetKeyDown("space") && isGroundedTop == true)
{
isGroundedBot = false;
GetComponent<Rigidbody2D>().AddForce(jumpVector * 150, ForceMode2D.Force);
}
if (Input.GetKeyDown("space") && isGroundedBot == true)
{
isGroundedTop = false;
GetComponent<Rigidbody2D>().AddForce(jumpVector2 * 150, ForceMode2D.Force);
}
}
This is my current script. And yes, I am very well aware it’s stupid to create two of everything, I just wanted to try get a quick preview of how it works. With this script, the player can jump up, but is not able to jump down again. I’m sure there’s a very logical explanation for this, but right now I’m unable to see what. Any ideas what I should use to create a non-accelerating movement up and down?