Making player object jump other than tapping the screen in android phones

Hello guys!

I was just wondering if there was a way to make a player object jump by using an accelerometer. This question just popped in my head a few days ago and it feels pretty rad to make the player jerk their phone up just to make their player object jump. So far most examples I’ve seen uses a touch/tap event to make the jump.

My player controller goes a little like this:

void Start(){
rb = GetComponent<Rigidbody> ();

void Update(){
Vector3 tilt = new Vector3(Input.acceleration.x, Input.acceleration.y, -Input.acceleration.z);

tilt = Quaternion.Euler (90,0,0) * tilt;

rb.AddForce (tilt * 4000);

The game I’m making is like a roll-a-ball whose orientation is in landscape, back of the phone parallel to the floor and home button on the right.

So is there any possible way to make that happen?

Any comment, reply is appreciated!

Thanks in advance!

You can do this

public float jumpMultiplier;
public float jumpTreshold;

void Update(){
	if(Input.accelerometer.normalized.y * jumpMultiplier >= jumpTreshold) {
		// Jump!!