June 2015
Intermediate to advanced
388 pages
7h 31m
English
To upgrade our detect method, we need to replace the return statement in the if(possibleCollision) block with the more precise detection code.
First, initialize radianAngle to be the radian equivalent of whichever direction (in degrees) our object is facing. The Math class uses radians as they are more mathematically useful in calculations than the easier to visualize degree measurement.
The variables cosAngle and sinAngle are just what the name suggests, and are used in the block of code which follows this one.
It is worth mentioning that the Math.cos() and Math.sin() methods are relatively time consuming. We can speed up our collision detection class by precomputing 360 values for both sin and cos ...
Read now
Unlock full access