I am developing an android game and I am using this code for the character to go above along y axis when i touch my phone.
var thrust=0;
var leftMoveIntensity =-0.05;
var rightMoveIntensity =0;
function Update() {
var rb=GetComponent.<Rigidbody>();
//spin the sphere all the time
//this.transform.Rotate(0,rotateSpeed*Time.deltaTime,0);
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved) {
// Get movement of the finger since last frame
var touchDeltaPosition = Input.GetTouch(0).deltaPosition;
// Move object across XY plane
rb.AddForce(0,0.05 * thrust,0);
}
if(Input.GetKey("a"))
{
transform.Translate(leftMoveIntensity*Time.deltaTime,0,0);
}
if(Input.GetKey("d"))
{
transform.Translate(rightMoveIntensity*Time.deltaTime,0,0);
}
if (Input.GetKey("s"))
{
rb.AddForce(0,-0.05*thrust,0);
}
}
This is working great only if I turn off gravity for the ball. As soon as I launch the game, gravity becomes superior than touch and my character falls down. However if I turn off gravity and then touch it works properly.
Can someone suggest me whats is wrong?
Thanks a lot for your time.