2D Toolkit Forum
2D Toolkit => Support => Topic started by: tellemstevedave on June 08, 2013, 08:39:45 pm
-
I'm trying to shoot a ray from the 2ktdcamera to see if the mouse it colliding with my sprite. It doesn't work correctly so I'm drawing the line in yellow. It appears offset from the screen a bunch. Notice how high up the yellow line is in the scene view.
Here's my relevant code:
public Camera gameCamera; // 2dtk camera set from editor
ray = gameCamera.ScreenPointToRay(touchPosition);
if (collider.Raycast(ray, out(hit), 10000.0f)){
overObject = true;
}
else{
overObject = false;
}
Debug.DrawRay(ray.origin, ray.direction * 10, Color.yellow);
Any thoughts on what is going wrong would be awesome. Thanks.
(http://)
-
Nope, as far as I can tell that should be correct.
It might be worth trying manually intersecting the ray -> plane where the collider is, and then see if you get sensible intersection positions there?
-
Thanks for the quick reply!
It turns out if I separate the game cam it looks like the projection is correct and goes through the ship. I don't know why the ray doesn't detect the mesh collision on the ship though.
-
Possibly because it doesn't have a collider cap? Its off by default in 1.xx
You can enable it in the sprite collection editor.
-
That did it! Thanks. Man that was confusing. I had no idea collider cap did that. If it sad collision side or something I might have got the hint.
Thanks!
-
But is that really the side? I'd think of the left/right edge of the collider a "side" - this is relating to depth isn't it.
In any case, its on by default in 2.0 - we've had enough confusion with this ;)