I try to make clone of Geometry dash game.Geometry dash game is jumping in parabolic way and i try to simulate jumping of square so i write this script :
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour {
public float speed;
public float jumpPower;
private Rigidbody2D body2d;
private bool grounded = false;
// Use this for initialization
void Start () {
body2d = this.GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void FixedUpdate () {
body2d.velocity = Vector2.right * speed;
if (Input.GetMouseButton(0) && grounded)
{
body2d.AddForce(Vector2.up * jumpPower);
}
}
private void OnCollisionStay2D(Collision2D collision)
{
if(collision.gameObject.tag == "ground")
{
grounded = true;
}
}
private void OnCollisionExit2D(Collision2D collision)
{
if (collision.gameObject.tag == "ground")
{
grounded = false;
}
}
}
but it dosent jump like geometry dash. geometry dash jump a little also it moves a little forward. but in my script it jump fast and move down . can any body help me how to make this jump like that game.geometry dash game