   Probability Implementation
  Dear alli am working on 2D missile trajectory simulator. before launching the missile the user also enter the hitting probability of the missile to the target. i am not getting how to implement this probability logic in my application so that some time it hits and some time its misses according to the entered probability. the game cycle time is 1 second.Thanks in advance   
  You could have the user enter a probability on the form "N out of K", for example "1 out of 100". Then, using a random number generator with uniform distribution, generate a random number between 1 and K. If the number is <= N, you consider that a hit. Now how to compute the correct vs incorrect trajectory is implementation-dependent, but you could introduce a random error in the angle when the missile is not meant to hit (an error so great, of course, as to making it miss the target).   ;  Re: coolshamimIf you are simulating the trajectory of a non-guided surface-to-surface missile, the chance to miss the target is proportional to the distance. The farther the target is, the more likely it will miss. If the only source of error is the initial firing angle:After you know the distance to the target and the size of the target, you can know what angles are required to hit the edges of the target area. You do this by using the same physics equations that gives you the position of the missile each second, set the destination position and solve for the initial angle.The shape of the possible impact zone:2D Side view:The shape of the impact zone is linear, but the possibility to land on each position within the zone is not linear. If the mean of the initial angle results in hitting the target perfectly, the shape of the possible landing zone is egg-shape. If the game is in side view, the target area is a number segment within the number segment of the possible impact zone. When you calculate the intial angles required to hit one the boundary of the target, you will see that they are not symmetrical about the dead center of the target. However, from those angles and your desired hit ratio, you can get how much the initial angle needs to vary to give you the result.2D Top view:The shape of the impact zone is egg-shape, but a target area is usually specified by a circular area. The two shapes do not match up nicely because your target surface is not necessarily tangent to the tragectory of the missile. If your missile is like a tennis ball flying in vacuum, to get the  variation in the initial angle required to hit a circular area within an oval zone, you would integrate the intensity over the area of the target to get the 'mass'. Imagine a flashlight shining on a slanted surface, the points closer to the flashlight get more light. Similarly, if you fire 10000 missiles, the area closer to the launcher gets more hit per unit area.Realistic trajectories:A missile is not like a tennis ball thrown in vacuum because the missile propels itself. It flies itself to a height and when it is close to the target, it dives. I don't know the actual shape of the trajectory. It depends on the distance and whether the missile regulates itself to fly at certain height (as low or as high as possible). The point is once you know how your missile ought to fly, you get the equations and solve for the permissible variations in the parameters at each time frame. It is easier to tell how likely a missile will hit a target given the variables. You are doing it backward, which makes it a harder problem. To simplify the problem, you could assume that while the missile is cruising, it is flying perfectly because it is correcting itself. The error comes only when the missile decies to dive. From there, the missile freefalls, starting at a horizontal position. By the time the missile hits the ground, the trajectory will be almost perpendicular. The source of error comes from the missile's knowledge of its own position and speed. For example, if the missile thinks that it is closer to the target than it really is, it would start freefall too early and falls short.   