- Home /
reading heading in Web browser with JavaScript
I'm embedding a Unity world on a Web page, placing people at certain landmarks in the world (which they've already explored), and then asking them to rotate around and point using cross hairs to other out-of-sight landmarks. When they click, I want to trigger a JavaScript function to read the current heading of the camera/first-person-controller and send it to JavaScript in the browser (to then send to the server). Can anyone point me to the API calls to get the heading (ideally for the center of the screen, where the cross hairs will be)? A bit of sample code would be even better! Thanks.
Why are you using JavaScript to send data to the server? Wouldn't it be simpler to just use Unitys built-in WWWForm class?
Answer by Ashkan_gc · May 14, 2010 at 08:07 PM
what do you mean by camera heading? do you want to see what object the camera is looking toward? if yes you can trace a ray from camera to see what will collide with it.
var r = camera.ScreenPointToRay (Vector3(0,0,0)); //mid of the screen
then use Physics.Raycast to cast the ray and see the result something like this
var hits : RaycastHits[] = Physics.RaycastAll (r);
then you can check different attributes of all
Your answer
![](https://koobas.hobune.stream/wayback/20220612234929im_/https://answers.unity.com/themes/thub/images/avi.jpg)