Question by
ImNotARana · Oct 30, 2018 at 01:13 AM ·
playerprogrammingjumphow
How to make the player can use flutter Jump like Yoshi in Super Mario World?
I'm new in game development and I tried to do something like Yoshi's flutter jump, but I can't do something functional. I mean, I want something like this: https://www.mariowiki.com/images/f/f5/Yoshi_Flutter_Jump_Artwork.png
public class Player : MonoBehaviour {
private Rigidbody2D rb2d;
public Vector3 velocity;
public Collision collision;
public float WalkSpeed = 0.5f;
public Vector3 jump;
public float JumpSpeed = 8;
public float JumpForce = 100;
public float JumpDuration;
public bool isGrounded;
public bool isFalling;
void Start () {
rb2d = GetComponent<Rigidbody2D>();
rb2d.velocity = new Vector3(0, 10, 0);
jump = new Vector3 (0.0f, 1.5f, 0.0f);
JumpDuration = 0.5f;
}
void Update () {
WalkMove ();
Jump ();
CheckFall ();
CheckGround ();
}
void WalkMove()
{
//WalkLeft
if (Input.GetKey (KeyCode.LeftArrow)) {
rb2d.transform.Translate (-Vector2.left * 2f * -WalkSpeed * Time.deltaTime);
}
//WalkRight
if (Input.GetKey (KeyCode.RightArrow)) {
rb2d.transform.Translate (Vector2.right * 2f * WalkSpeed * Time.deltaTime);
}
}
void Jump()
{
if (Input.GetKey (KeyCode.UpArrow) || Input.GetKey (KeyCode.Space) && isGrounded == true) {
rb2d.transform.Translate (JumpForce * jump * Time.deltaTime);
if (transform.position.y == JumpDuration) {
rb2d.velocity = Vector3.zero;
}
}
}
void OnCollisionOn(Collision collision)
{
if (collision.gameObject.name == "Platform")
{
isGrounded = true;
}
}
void OnCollisionOut(Collision collision)
{
if (collision.gameObject.name != "Platform")
{
isGrounded = false;
}
}
void CheckFall()
{
if (rb2d.velocity.y < -0.1)//&& Jump
{
isFalling = true;
}
else
{
isFalling = false;
}
}
void CheckGround()
{
if (rb2d.velocity.y == 0)
{
isGrounded = true;
canBoost = false;
}
else
{
isGrounded = false;
canBoost = true;
}
}
}
Comment