I am making a variant of flappy bird.
The idea is to have my character to go up and down with mouse click, like Flappy Bird. It would start in the middle, without moving.
Once I press the button the player will be launched up. When it reaches the top of its way he goes down.
A couple of problems I had are.
Sometimes the player will just go up all the time.
Sometimes it will just go down.
I do not want for it to go up and because of the gravity, go each time less high and after go down, when the speed of it going up ends. I would like to have a movement like:
Mouse click - Go a bit up, then go down with the speed increasing as it goes down. Something really aggressive, lets say
Script:
using UnityEngine;
using System.Collections;
public class PlayerMovement : MonoBehaviour {
private bool hasStarted = false;
private bool goingUp = false;
private bool goingDown = false;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (hasStarted == false) {
this.transform.position = new Vector3(1,6,-1);
// Wait for a mouse press to launch.
if (Input.GetMouseButtonDown(0)) {
hasStarted = true;
goingUp = true;
}
}
if (hasStarted == true) {
if (Input.GetMouseButtonDown (0)) {
goingUp = true;
}
if (goingUp == true) {
print ("Launch Bird");
rigidbody2D.velocity = new Vector3 (0, 5, 0);
goingUp = false;
}
if (goingDown == true){
rigidbody2D.velocity = new Vector3 (0, -10, 0);
}
if (goingUp == false) {
goingDown = true;
}
if (goingUp = true) {
goingDown = false;
}
}
}
}