- Home /
Throw an object via touch/mouse flick
I've been trying to figure out the best way to record a swipe or mouse flick to capture its time and distance in order to set the objects velocity after the swipe/mouse flick ends, basically throwing the object. I know there are other questions on here regarding this, but I am still having difficulties applying it. I know I am just over-thinking this, but I am interested in how other, more experienced programmers would tackle this.
Here are my goals and requirements for this fuctionality:
object continues to move after touch according to velocity of swipe/mouse at previous frame
object is not influenced by gravity, but will need still need to interact (bounce) with other objects in the environment.
I have used distance and time captured from the previous frame, but I return a velocity of zero and I think that because many frames are passing per second, the difference between them are so minute that I'm returning a zero. Just a guess. I do not want to use the length of distance and time over the entire swipe/mouse because I can hold an object for a couple of seconds and then throw it, but because I held it in place for a period of time, it would throw off the velocity calculation.
I'm interested in seeing what some other programmers can come up with because I have reached the point that I'm lost in my own problem.
Some other things to consider:
I have a touch manager attached to the camera, and movement scripts attached to each object. Not sure if it is better to just capture touches with the camera to pass that info to the movement script on the object to calculate velocity and then execute the move, or to have the touch manager handle the calculations and the move.
Not sure if it is best to use rigidbody.addforce or transform.translate. Force seems safer because if two object collide after being thrown, they should bounce off each other correctly, where transform.translate would not take physics into account.
Anyway, thanks for reading and the help! I really appreciate it!
Your answer
Follow this Question
Related Questions
Different resolutions make the swipe of my player go at different speeds on different devices 0 Answers
Throw a ball in target bucket with swipe but with one drop Unity3D 2 Answers
Help with swiping for movement 1 Answer
Moving player using cam.ScreenToWorldPoint, with camera smooth following the player 1 Answer
swipe distance detection dont work 2 Answers