Hello Guest

Author Topic: Offset ray from 2dtk camera  (Read 4031 times)

tellemstevedave

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 4
    • View Profile
Offset ray from 2dtk camera
« 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.


unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Offset ray from 2dtk camera
« Reply #1 on: June 08, 2013, 10:27:19 pm »
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?

tellemstevedave

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Offset ray from 2dtk camera
« Reply #2 on: June 08, 2013, 10:52:35 pm »
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.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Offset ray from 2dtk camera
« Reply #3 on: June 08, 2013, 11:10:52 pm »
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.

tellemstevedave

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Offset ray from 2dtk camera
« Reply #4 on: June 08, 2013, 11:50:11 pm »
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!

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Offset ray from 2dtk camera
« Reply #5 on: June 09, 2013, 12:08:30 am »
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 ;)