# Bullet Accuracy

3 posts

 Hey guys, I was wondering if you happened to know what the math would be to have a bullets Direction remain within that of a given cone. For example I fire the gun and the bullet may travel slightly left or right of the intended direction. I tried several different things but with crazy effects. Sometimes my bullet would go completely left, or backward etc. Here is my function, which may be wrong. I tested with different numbers. ` private function move():void { this.x += Math.cos(Direction * Accuracy) * Power; this.y += Math.sin(Direction * Accuracy) * Power; } //And here's what the value of accuracy is. Accuracy = (Math.random() * Acc) - Acc ` my guess is either the function is close, Or its completely wrong lol. Also I was putting in 2 for Acc. Any ideas on how to make this work? To get an even positive/negative spread, the first thing you need is (Math.random() – 0.5) That’ll give a number between -0.5 and 0.5 Assuming Acc is some value in radians, you probably want to use `Accuracy = (math.random() - 0.5) * 2 * Acc;` to get a value betwen -Acc and Acc. Then add Accuracy to Direction instead of multiplying ` private function move():void { this.x += Math.cos(Direction + Accuracy) * Power; this.y += Math.sin(Direction + Accuracy) * Power; } ` So you’ll end up with something between Direction – Acc and Direction + Acc Awesome! that works much better than what I had. Lol I knew it was something incorrect in my math. Thank you!