# Collision with User Input and Object

I am curious on how to handle collision detection involving a moving target and user input. Basing myself in the mobile space, I get events from a set framework, but I do wonder about the amount of lag involved.

Say the object moves faster and faster, then position of the input and the object is very important. What I want to know is what is the best design for handling user input and then also the best way to make sure to accurately work out when the input point collides with the object, keeping threads in mind?

-

Your question is so vague that it cannot really be answered. However, you sound new so I'm going to try and help. Here is what I suggest you do if you truly want to make computer games:

I am curious on how to handle collision detection involving a moving target and user input... but I do wonder about the amount of lag involved.

Your first question tells me that you really need to read up on your Matrix mathematics, in all non trivial cases it will come down to some small Maths to work out if the users press on the screen was on an object. Usually by firing a projection through your world starting at the camera and seeing if it collides with anything. For Matrix Maths knowledge and vector calculus in general start with this good guide: Vector Math Tutorial for 3D Computer Graphics. (Those sixteen chapters give you the basics and it should take you a few months to learn that properly.)

About the lag issue: Maths on Computers is usually ridiculously fast. If you can find a good way to do it using some Maths then, in general, it will be fast code and result in little in the way of lag. If you suffer more lag despite that then it is probably an algorithmic problem and you should look into Complexity Theory and see if you algorithm are fast enough. All you probably need most of the time is Big-O notation and here is a good introductory tutorial (though there are better notes out there).

Say the object moves faster and faster, then position of the input and the object is very important. What I want to know is what is the best design for handling user input and then also the best way to make sure to accurately work out when the input point collides with the object, keeping threads in mind?

Once you know the Math, knowing how to handle collisions with 'jumping' objects due to high speed is relatively easy. Ask a new question about that specifically if it does not come easily to you; but only once you have read that Vector Calculus math above.

There is no 'best designs' for handling user input in games, just methods that work well for your particular game. Just try and make the simplest thing that will work and improve them only if you need to.

Now accuracy in video games! That is a real problem and one that requires true concentration and skill, if your game needs a high level of accuracy, and you are using floating point values like 'float' and 'double' to represent things then you will need to learn how to deal with those properly too otherwise you will see serious and subtle problems occur in your games. I would recommended looking at: Comparing Floating Point Numbers and other good articles on the topic too to see if, and how, it will effect you.

As for concurrency, well that completely depends on what parts of your program you think you can make concurrent and how you do it. Just minimise shared state and everything will be easier. There are concurrency best practices out there and they are included in any good concurrency tutorial, the rest is left as an exercise to the reader.

In the future, try and ask smaller questions with more details because it raises the possibility that somebody will be able to give you a definite answer. Keeping that in mind I hope this answer help and you should note that the road to game development if filled with learning many different and new topics so it will take some time but, if you enjoy programming, then it is a extremely fun journey.

-
I do apologise. I was trying to get a general idea of what others do. It seems whenever I do that I do seem to get vague. Thank you for your advice. – NebulaFox Mar 29 '11 at 9:23
@kuroutadori: No apology required, you did nothing wrong per say, just asked a very open ended question. At any rate keep asking questions and maybe read this: catb.org/~esr/faqs/smart-questions.html – Robert Massaioli Mar 29 '11 at 21:24