Unity 2D jumping only up
Hello, I am new at unity and I have the following issue: I am working in a game where is a circle moving inside another circle in rotation form. So I added a Jump function in my code but the problem is that is going only up. I want to create something like Run Around made by CrazyLabs
This is my player script. I got the player connected with a point effector 2D to make the rotation inside the other circle.
public int moveSpeed = 0;
Rigidbody2D rb;
private float moveInput;
enum PlayerState{
Standing, Jumping, Falling
}
PlayerState currentState = PlayerState.Falling;
// Use this for initialization
void Start () {
rb = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void FixedUpdate ()
{
MovePlayer();
if(Input.GetKey(KeyCode.Space)){
GetComponent<Rigidbody2D>().AddForce(Vector2.up * moveSpeed);
}
}
void Update()
{
GetInput();
}
void GetInput()
{
if (Input.GetMouseButton(0))
{
if (currentState == PlayerState.Standing)
{
Jump();
}
}
}
void Jump()
{
currentState = PlayerState.Jumping;
rb.velocity = new Vector2(0,-10);
}
void MovePlayer()
{
this.transform.position += transform.right * moveSpeed * Time.deltaTime;
}
void OnCollisionEnter2D(Collision2D other)
{
currentState = PlayerState.Standing;
}
Comment