Perhaps it is because each frame when mouse button is down, you are applying a force down and up. I would pace your if() above the stuff not in if and add in a return.
ok avoid what i said before.
You mean that goes up like flickering movement!? is there gravity ?
I made a Test here!
I created a new project and just apply this script (Below) to an brand new cube. It jump so smotth.
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(Rigidbody))]
public class Jump : MonoBehaviour {
public float _Jump = 1000f;
void Update () {
if (Input.GetMouseButtonDown(0)) {
Debug.Log("Jumping...");
rigidbody.AddForce(Vector3.up * _Jump);
}
}
}
Maybe something else on your code or another script is messing with your object.
Maybe the problem is that you using Vector2 and not Vector3, since its Rigidbody and not Rigidbody2D. I don’t know!
using UnityEngine;
using System.Collections;
public class game : MonoBehaviour {
public float speed = 15.0F;
public int start = 0;
public int alive = 0;
public float fallspeed = 14.0F;
public float upspeed = 14.0F;
// Use this for initialization
void Start () {
GameStart();
}
// Update is called once per frame
void Update () {
if(Input.GetMouseButtonDown(0)){
if(start == 1){
Destroy(GameObject.Find("tapLeft"));
Destroy(GameObject.Find("tapRight"));
Destroy(GameObject.Find("tapTick"));
start = 0;
alive = 1;
}
}
if (alive == 1){
rigidbody.AddForce(Vector2.right * speed);
if(Input.GetMouseButtonDown(0)){
rigidbody.AddForce(Vector2.up * upspeed);
} else {
rigidbody.AddForce(Vector3.down * fallspeed);
}
}
}
public void GameStart(){
alive = 0;
start = 1;
}
}
I see… The main problem is that addForce(Vector3.Down); remove it.
then go to Edit > Project Settings > Physics 2D make sure there are gravity amount set!
Remember that your objects must have Rigidbody2D to be affectted by gravity.
You don’t have to apply force down since there is gravity to do this for you.
then your project should work fine. You just have to change the jump variable to a higher value as you please.
let me know if that work.