- Home /
Swipe and Hit Object in Direction
I am looking for a way to touch (or mouse click) swipe over an object to knock it in the direction of the swipe.
The premise is that there will be a sphere on screen, within some kind of box-like boundaries, and the player can swipe it to fling it around the box and bounce off the walls etc. The touch code is the one I am least sure of though. I know this is relatively simple, but any points in the right direction would be appreciated.
Answer by syclamoth · Oct 14, 2011 at 06:17 AM
Well, you could have a long capsule-collider which 'comes out' of the camera, using 'ViewportToRay' as the base from which to create it. You'd have to set up a kinematic rigidbody, but as long as the other object in question is a rigidbody that should work outside of extreme circumstances.
Of course, there is still the problem of 'phasing' through, if the player swipes too fast. For that, I would do something more complex, like use either capsuleCast or SphereCast to trace an approximate line between frames, and then apply the forces manually using the contact points returned from that.
Your answer

Follow this Question
Related Questions
Unity2D iOS Dragable items by touch 0 Answers
Different swipe speeds on different resolutions 1 Answer
Is there a way to optimize Input.GetAxis on windows phone? 1 Answer
(Android) Swiping direction 1 Answer
Multitouch drag object 0 Answers