Question by
howllingpuddle · Nov 30, 2019 at 11:11 AM ·
beginnernewbie
Okay so i followed a some what old video on how to jump and for some reason my character just goes up and i cant find out why
This is the video https://www.youtube.com/watch?v=j111eKN8sJw&t=
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class movement : MonoBehaviour
{
private Rigidbody2D rb;
public float speed;
public float jumpForce;
private float moveInput;
private bool isgrounded;
public Transform feetPos;
public float checkRadius;
public LayerMask whatIsGround;
private float jumpTimeCounter;
public float jumpTime;
private bool isJumping;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
void FixedUpdate()
{
moveInput = Input.GetAxis("Horizontal");
rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);
}
void Update()
{
isgrounded = Physics2D.OverlapCircle(feetPos.position, checkRadius, whatIsGround);
if (isgrounded == true && Input.GetKeyDown(KeyCode.Space))
isJumping = true;
jumpTimeCounter = jumpTime;
rb.velocity = Vector2.up * jumpForce;
{
if (Input.GetKey(KeyCode.Space) && isJumping == true) {
if (jumpTimeCounter > 0)
{
rb.velocity = Vector2.up * jumpForce;
jumpTimeCounter -= Time.deltaTime;
}
else
{
isJumping = false;
}
{
if (Input.GetKeyUp(KeyCode.Space))
{
isJumping = false;
}
}
}
}
}
}
this is what i used for the movement
Comment