Jump script basically not working
I have never made a jump script in my life since i always did top down games and my first attempt isn't going to smoothly, i do not know why but Vector2.up is not working and only way to make the character jump is by using Addforce, which is awful. It just teleports the player up basically, i never used AddForce either since i always just used the Axis so this was stupidly unexplainable to me, i tried to do it in impulse and it still teleports the player Rigidbody2D body;
float horizontal;
float vertical;
public bool facingRight = true;
public float jumpForce = 30;
public bool Grounded;
public float runSpeed = 20.0f;
public Transform FeetPos;
public float CheckRadius;
public LayerMask GroundLejer;
public BoxCollider2D check;
public Vector3 jump;
void Start()
{
body = GetComponent<Rigidbody2D>();
jump = new Vector3(0.0f, 2.0f, 0.0f);
}
void Update()
{
if (Input.GetKeyDown(KeyCode.E))
{
body.AddForce(new Vector2(0f, jumpForce));
}
horizontal = Input.GetAxisRaw("Horizontal");
vertical = Input.GetAxisRaw("Vertical");
if (Input.GetKey(KeyCode.LeftShift))
{
runSpeed = 2;
}
else
{
runSpeed = 1;
}
Grounded = Physics2D.OverlapCircle(FeetPos.position, CheckRadius, GroundLejer);
}
private void FixedUpdate()
{
body.velocity = new Vector2(horizontal * runSpeed, vertical * runSpeed);
Flip(horizontal);
}
private void Flip(float horizontal)
{
if (horizontal > 0 && facingRight)
{
facingRight = !facingRight;
Vector3 theScale = transform.localScale;
theScale.x = 1;
transform.localScale = theScale;
}
else if (horizontal < 0 && !facingRight)
{
facingRight = !facingRight;
Vector3 theScale = transform.localScale;
theScale.x = -1;
transform.localScale = theScale;
}
}
I just want to make it so i can continue on with the game and every video and topic about it does not help, i am rethinking just remaking the whole script. Also it could be cause of the player gameobject but there is nothing wrong with it tho.
Your answer
Follow this Question
Related Questions
Basic MOVE and JUMP script (Jump trouble) 2 Answers
Grounded and pressing "jump" not working? 1 Answer
Character keeps flying after jumping 0 Answers
This is frustrating 2 Answers
I have a problem with in air movement 0 Answers