Importing coordinates from a external file and using them to reposition the camera

Hi Everyone,

While I’m a good programmer, I’m still getting used to the link between scripting and the objects within the level.
Simply put I am trying to move the camera to coordinates taken from a external ascii file. Where do I start with this? I know I have to make a script within the main camera but I am unsure how to reference the camera position from within this script. In addition to this I am unsure how to import a ascii file that will update constantly at run time. I am working on the Android platform.

Many Thanks

James

What kind of programming do you normally do? I’m not sure that I’d be messing with ASCII files if there was a need for it to be constantly updated… The amount of resources you’ll spend reading and writing to that file repeatedly suggests there’s gotta be a better way. Or is a remote text file your only option?

What are you actually trying to do here? As in, big picture.

Thanks for the reply,

Best described I do a lot of academic programming, the fortrans and c of this world, haven’t done object orientated for a while! Recently picked up Android Studio and getting on with that nicely though.

So big picture for this is a simple AR tech test. I’ve got a app which does indoor positioning and outputs the position to a ascii file on the phone. The plan is to have that running in the background, output my position in the room. Next Unity will take in this information and reposition the camera in scene according to that position. I don’t need to write to the file at all.

Next step is I intend to use the google cardboard demo scene which nicely allows the use of the camera sensors for pitch and yaw of the phone combining this with positioning changing according my IPS app means I should be able to walk around my scene using the phone. The final step would be turn on the phone camera through Unity thereby creating a AR effect without using image positioning. That’s the hope anyway!

If you have any examples which could do the above or code snippets it would most certainly help me along the way!

James

OK, given what you’re trying to do here I think this approach is reasonable.

Your script on the camera object can access the camera position as simply “transform.position”. You can open and read a file using standard C# file I/O. So, periodically read the file, parse out the position it contains, and assign it to transform.position, and Bob’s your uncle.

1 Like

Hi Guys,
Got it working last night, took a bit of tinkering with the path, but was all good in the end!

Thanks for the help
James

1 Like