For your joystick issue, I'm not sure what you mean. Can you describe the problem again in more detail? Tell us which joystick you are using, where it's connected, when you get the values you're seeing, how you're determining what the values are, and what you mean by "on an angle" and "goes forward".
Code for using the gear tooth sensor isn't readily available in a "plug and play" form, but it's easy to change what
is available. Grab a copy of Kevin Watson's encoder code from
his web site, follow the directions for installing it into your MPLab project, configure the sensors for digital inputs 1 and 2, and remove the test for the Phase B signal level from the interrupt service routine. You want it always to increment the count when the interrupt occurs.