hi, so i have this really simple 2D android game with a ball that uses the accelerometer to move from side to side, and i was wondering how i would get the ball to jump with just a touch anywhere on the screen (in Java). Here is my code so far:
#pragma strict
var speed = .2;
private var circ : float;
private var previousPosition : Vector3;
@script RequireComponent(Rigidbody)
function Start()
{
//Find the circumference of the circle so that the circle can be rotated the appropriate amount when rolling
circ = 2 * Mathf.PI * collider.bounds.extents.x;
previousPosition = transform.position;
}
function Update () {
var dir : Vector3 = Vector3.zero;
dir.x = -Input.acceleration.y*.2;
transform.position.x += dir.x;
rigidbody.AddForce(dir * speed * Time.deltaTime);
}
function LateUpdate()
{
var movement : Vector3 = transform.position - previousPosition;
movement = Vector3(movement.z,0, -movement.x);
transform.Rotate(movement / circ * 360, Space.World);
previousPosition = transform.position;
}