I'm making a 3d hockey game for the iPhone, and I'm having a problem with my movement. I want it so that the active player moves to the place last touched. However, after a little while of playing, the z co-ordinate of the hit will wind up somewhere below the screen. I've made it output the screen positions of the touch, and that's not the problem. Any suggestions on how I should approach this problem? gameInfo.touchPoint is just a Vector3 I made for the GUI so that I can see the hit position in the GUI until this is solved. What's going on is that I'll touch a point that has a z of 5, and suddenly it'll think I'm touching at -13, then eventually bring itself back to 5. After this code is where I do my vector subtraction to get the character moving, but it seems like the problem is with the hit itself.
EDIT I added some script to trace out what I'm touching (gameInfo.touchObject = hit.transform.name; and then stuff to draw it through the GUI), and I'm still touching the ice even as this is happening. In another test, I rotated the camera so it was directly overhead, and this continued to happen.
Here's the code in question:
As spinaljack suggests, the best way to find out why a Ray isn't triggering is to return name of the object your Ray is hitting. This can help your debug any confusing collision problems or problems with your code.
Here's a simple way to return what the raycast hits:
answered Jul 14 '10 at 04:34 PM
I would also ask about the type of colliders you have. Is the collider for your ground a plane or a box? Plane's are expensive for collision ;)
answered Aug 29 '10 at 03:05 AM