# How to add a constant horizontal force just like gravity?

I want to add a constant horizontal force, just like gravity to a projectile or a sphere moving in 3d space, which will make the projectile or ball or sphere or whatever be influenced by this force so that it will curl in the direction of the constant horizontal force. I have this code which will add force to the object on swiping the screen, but it doesnt drift/curl or whatever you may call it:

var anglex : float;
var angley : float;
var elevationAngle : Vector3;

function FixedUpdate () {
if(Input.touchCount>0 && Input.GetTouch(0).phase == TouchPhase.Ended)
{
var touchdeltaposition: Vector2 = Input.GetTouch(0).deltaPosition;
anglex = touchdeltaposition.x * Time.deltaTime *2.0;
angley = touchdeltaposition.y * Time.deltaTime *5.0;
Debug.Log(angley);
elevationAngle = Vector3(anglex,angley,0);
rigidbody.velocity = transform.TransformDirection(Vector3(anglex,angley,angley ));
var elevation : Vector3 = Quaternion.Euler(elevationAngle) * transform.forward;
}
}


I feel this is simple, but I'm just not able to turn the crank.

• Describe a bit more what's happening. Are your Debug statements being executed? Is the object being affected at all? Have you tried some visual debugging to ensure you're applying the force in the correct direction? – MichaelHouse Jul 9 '14 at 14:27
• @Byte56 Actually I didn't test it then, but when I tested it now, it doesn't seem to work, toucheddeltaposition is zero regardless of the swipe position, direction, magnitude... What am I doing wrong? – gameOne Jul 10 '14 at 0:22

• Attach the debugger, check out the values of your variables. Specifically, I'd poke around Input.GetTouch to see if there are any other touches available and what the value of deltaPosition is, and check the calculations along the way. – user45357 Jul 10 '14 at 15:28