I’m trying figure out how go about doing a crosshar for my game. My game is 2d side scroller. I got the cross hair working easy enough, but I’m confused about the whole camera.worldtoscreenpoint and ray casting. I don’t understand it or rather a method to apply it. if any one knows a tutorial on subject or book please lead me in right direction. I not asking for hand me out. I’ll put time in learning it and I’ve googled it about three hours now, but I just silly questions on Unity answers…Kind like my silly question haha.
Specifically what are you trying to do? You’re going to need to give us more information, because you’ve asked what something does- but you mention raycasting in the same sentence, and WorldToScreenPoint has nothing to do with raycasting- which is probably why you can’t find any information about it.
Since you asked though, WorldToScreenPoint returns the screen coordinates of an object. Simple as that. If you have a character running around on screen, his 3D position might be (405.72, 88.91, 65.98), but on screen he will have an XY position that fits within your game’s resolution. 0,0 being the bottom left corner of the window, and the top right being whatever the max width and height of the resolution is.
So specifically, what are you trying to do? A liero style side scroller, where you run around and use the mouse to aim/shoot? If that’s the case, you dont’ need to raycast at all, you can just measure the angle (in screen space) of the player’s position on screen with the mouse, and get the dot product. You can also simply transform your mouse coordinates into 3D space and just set the missing axis to match whatever your player’s is.
Without anymore info, it’s all just speculation though.
First I apologize about the confusion and thanks for summing up WorldToScreenPoint for me. Basically my idea is to shoot enemy’s that are coming at the main character. you have to protect him. I’m using a cannon that you control. I basically just want it as to wherever my cross hair is my cannon ball will fire that direction so I have to figure like you said which would be the best solution though I was think of WorldToScreenCoord considering the cross hair on the mouse, but I have never fooled with raycasting either. In nut shell wherever my mouse is on the screen I need a cannonball to be fired at that location.