I am trying to throw a gameobject on swipe direction similar to paper toss game
i tried Addforce but i cant throw at swipe direction please suggest any solution.
bottom line : i want to throw object at enemy by swiping.
please help me through
initPos = Input.mousePosition;
finalPos = Input.mousePosition;
finalPos = Camera.main.ScreenToWorldPoint(finalPos);
rigidbodyBox = ball.AddComponent("Rigidbody") as Rigidbody;
rigidbodyBox.mass = 5;
ball.rigidbody.AddForce(???????)//what should i pass here //******
Track the movement of the finger on the touch pad. This will allow you to work out the direction of the swipe. Convert that (2d) direction vector into a 3d direction vector and apply the force in that direction.
Maybe something like this could work:
gameObject.GetComponent<ConstantForce>.force = <YOUR SWIPE>.transform.TransformDirection(Vector3.forward);
It works for my as I have a ball that I throw in my arrows direction (which I can control with Left and Right keys). For me it looks like this:
Ball.GetComponent<ConstantForce>.force = Arrow.transform.TransformDirection(Vector3.forward);
This will throw in the direction of the arrow.