i want to use android GPS coords to make a camera motion in unity
i have made a ar game that use Gyro as camera rotation an now what i want is to walk around unity virtual world, i know that GPS coords is degrees then should not work as is, however, someone know a formula to make its work? ive downloaded this plugin but they convert a littlest decimal degrees to a thousand "meters"
https://github.com/MichaelTaylor3D/UnityGPSConverter/blob/master/GPSEncoder.cs
Related
I need to develop a Unity Android APP to help in agricultural guidance and I am facing some very especific GPS problems, let me just explain the project to you.
It needs to use accurate GPS data to guide you on the fields
It won't be able to connect the ethernet, I just get the Latitude
and Longitude, the map is just a infinite ground plane (already
made) not some real world map.
The "player" (tractor, machine,...) needs to move on the Unity
space (not the ground texture, the player itself) because I need to draw a Trail
Renderer for my planting path (already made).
So I have a very specific situation where every API I found moves the ground texture instead of the player object. I need to transform my Latitude and Longitude changes (movement) into Unity space movement, I need to accurately move (transform.Translate) my player on the Vector3 coordinates every time the GPS coordinates changes.
This code is about what I have right now.
//so in the Update method
if (newLat != lastLat || newLong != lastLong){
//what do I do here?
EDIT 1:
This guy has the same question as mine on an old post, but got no response.
After reading this code, I think you can just get the latitude and the longitude and set the position of an object, not move.
By that I mean something like this:
// Get the GPS values (I'm not sure if you can do it like this, I copied it from the code you linked)
latitude = Input.location.lastData.latitude;
longitude = Input.location.lastData.longitude;
// Set the position of a GameObject using the GPS values
transform.position = new Vector3(latitude , 0, longitude);
I am working on a project where I need to move an object relative to the movement of the camera. I need it to be similar to an AR camera, as if the object was staying still even if the phone is moving.
Does anyone have any idea?
I can't use the gyroscope, as it has low compatibility with Android devices. I am trying to use the accelerometer, but it is not working because the object moves right/left when turning the phone like in a diagonal position, and not when staying vertical and rotating.
This is the code I am using:
void Update()
{
transform.Translate(Input.acceleration.x,0 ,0);
}
Hey guys how do I find the rotation of the phone with Google Cardboard SDK in Unity3D, like the way the persons head is facing? I need to find if it is facing more towards the east, the west, or the north. Do I find the rotation of the head, or the parent Main camera?
The Cardboard class contains a property called HeadRotation which is a Quaternion.
Quaternion crtRot = youCardboardController.HeadRotation;
To use its rotation like you'd in Unity with directional vectors you may simply multiply it by Vector3.forward.
Vector3 lookDir = crtRot * Vector3.forward;
Visualizing the vector in editor might help narrow down issues
void Update () {
// ..
Debug.DrawRay( pos, lookDir * 100, Color.blue );
// ..
}
From here you only need to know where North is, in meaning of the facing vector. Do a Vector3.Angle() and you have the angle between your avatar's and North's vector. You might want to evaluate both vectors with their y axes set to 0.
You could also use Vector3.Dot() (the dot product) to determine how much both vectors look into the same direction.
I had an issue with HeadPosition, which wasn't updated properly. So if you operate from HeadPosition keep in mind it may stick to 0,0,0 .
Take Head.transform.rotation - that's the orientation of the user's head.
I'm not really sure what do you mean by North or West. If the mobile device has a magnetometer, then maybe you could read it's data to determine where North is, but I've never done that
It would be the rotation of the Head object, although the Main Camera usually has the same rotation.
But if you want the direction relative to the real world, that information is not available in the SDK. The compass cannot be used because of the magnet, so there is no way to get the real direction.
Just take the rotation angle of the main camera in the scene. It will gives you the head rotation angles with respect to x, y and z axis.
In GVR based VR scenes the system is internally rotating the camera with respect to our head movements. So it's easy to get the head rotation using main camera rotation angles.
For that,
//local rotation of the Transform of the camera
Camera.main.transform.localEulerAngles.y
//The world Y rotation
Camera.main.transform.rotation.y
I'm currently working on a camera for a game. But I got stuck at the rotation.
When I move my mouse across the x- or y-axis, I want the camera to rotate around my character.
What would be a formula to calculate this vector, if the distance to the character is always the same?
I am doing this in Unity, with C#, if this is of any help.
this function may help: transform.RotateAround(Vector3 axis, float degree)
you can read the Unity Script Reference for more info.
-oh and I think you should tag your next questions with "unity3d"
but you get the best Unity3d-help at UnityAnswers-Forum http://answers.unity3d.com/index.html.
You can utilise spherical coordinates — they seem to fit more than Euler angles for the purpose of camera movement. The Cartesian vector which you need can be obtained by simple formulas as described there.
i am designing a 3d game in xna. Once my spaceship moves 180 degrees in the Y driection( not x or z), then i get a mirror image.. i dont know why this happens but this happens wether this is in an environment or wether the camera follows the spaceship or not. the whole environment changes view and becomes a mirror image of the previous view. Does anyone know why?
Edit: well What kind of info do you need? there is the camera matrices , and the spaceship matrices although it seems that everything is changing , and the controls of course.
it sounds like you might be gimbal locked ... lots of info online (sorry for the brief answer)
http://www.bing.com/search?setmkt=en-US&q=XNA+gimbal+lock