- Home /
Worldtoscreenpoint.....
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.
Answer by testure · Jun 29, 2011 at 05:35 AM
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.
Answer by Mr.Capture · Jun 29, 2011 at 06:01 AM
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.
Your answer
![](https://koobas.hobune.stream/wayback/20220612125034im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
screen coord 1 Answer
Inaccurate WorldToScreenPoint 0 Answers
2D Aiming with a mouse angle problem 1 Answer
Drawing crosshairs and other 2D graphics onto the screen? 2 Answers