- Home /
2d Beat Em Up Jump Functionality
Hi, I am working on my first unity game after completing a bunch of tutorials like burgzergarcade and a couple of 2d tutorials that I have found. I am building a 2d brawler like streets of rage, final fight etc and I am having problems getting my character to jump properly. I basically limit the characters movement using MathF.Clamp in the update but when I call my jump function (also being checked in update). The character will jump perfectly but then not be able to move anymore upwards, even though the MathF.Clamp limit is larger then where I landed (ie the playarea should be bigger but is being limited). Here is my code, I would appreciate any help given!
void Update()
{
//sets player boundries in the scene
Vector3 pos = transform.position;
pos.y = Mathf.Clamp(pos.y, -22.0f, -7.0f);
pos.x = Mathf.Clamp(pos.x, minX, 100f);
transform.position = pos;
movement();
combat();
jumpUp();
}
public void jumpUp()
{
if (Input.GetKeyDown("space"))
{
jumpStart = transform.position.y;
moveDirection.y = jump;
}
if (transform.position.y >= jumpStart)
{
moveDirection.y -= gravity * Time.deltaTime;
transform.Translate(moveDirection * Time.deltaTime);
}
}
Your answer
Follow this Question
Related Questions
GetButtonDown not always firing 1 Answer
Sprite Sheet animation without fancy add-ons 1 Answer
Multiple Cars not working 1 Answer
iTween gradual jump 2D 0 Answers