Hi, guys. I’m a beginner to Unity, and I’m trying to create a Doodle Jump-like game, with many differences of course. I’m facing 2 issues, however.
The first is that the upward jump is very sudden, and I want it to be more natural.
The second is that when the level begins, I want the player sprite to automatically jump upwards from the bottom of the screen. I have added an AddForce in the start method, but the sprite simply falls downwards.
I’m stumped, so please suggest ways I can make this work.
Here is my code - note that it is incomplete.
public class Player : MonoBehaviour {
Vector2 jumper = new Vector2(0, 2000);
public static bool dead = false;
public float speed;
public bool onPlat = false;
void Start ()
{
GetComponent<Rigidbody2D>().AddForce(new Vector2(0, 1000),ForceMode2D.Force);
}
private void FixedUpdate()
{
if(dead==false)
{
Vector2 movement = new Vector2(Input.acceleration.x, -5);
GetComponent<Rigidbody2D>().velocity = movement * speed;
if (onPlat == true)
{
GetComponent<Rigidbody2D>().AddForce(jumper*Time.fixedDeltaTime, ForceMode2D.Impulse);
}
}
}
private void OnCollisionEnter2D(Collision2D collision)
{
onPlat = true;
}
private void OnCollisionExit2D(Collision2D collision)
{
onPlat = false;
}
}