- Home /
ITween and Unity Postions.
Hi there,
I'm trying to get the camera to move from one position to another position. I'm using Itween to do this action.
What I want to Happen is :
- Be able to retrieve the selected GameObject's.
- Retrieve the Currently used camera.
- Use ITween to Moveto the Selected GameObject's position.
That's it...
But what is currently happening is:
- I Click on the Gameobject I want to move to. and get reference to it
- I Get Reference to the camera's GameObject via
Camera.Main.gameObject;
- I Click a Move To button, and it starts to move to a random locaiton.
(not cool..)
So I set a Test Exception to throw when I want to start the move. So I can view the position of the selected GameObject.
Original Position of the GameObject is (-34351.24 , 4.752806 , 789.6055):Vector3,
Positions Shown by Exception Test are changing when I turn the camera with the mouse look.
- Looking at where the game object is. = Exception: (0.1, 0.2, 28213.2):Vector3
- Looking to the side a little bit is = Exception: (0.1, 0.2, 28213.2):vector3
Code from the GUI button
if (GUI.Button(new Rect(160.0f,10.0f,100.0f,20.0f) , new GUIContent("Move To")))
{
cam = Camera.main.gameObject;
throw new Exception(SelectedGameObject.transform.position.ToString());
if (SelectedGameObject == null)
{
throw new Exception("Selected GameObject was not passed to GUI_selection");
}
else if (cam == null)
{
throw new Exception("Selected Camera was not passed to GUI_selection");
}
//Debug.Log(cam.ToString());
//iTween.lookTo(cam, 7, null, SelectedGameObject.transform.position);
iTween.moveTo(cam, 7, null, SelectedGameObject.transform.position, iTween.EasingType.easeInCubic);
//iTween.moveToUpdate(cam, 7.0f, SelectedGameObject.transform.position, iTween.AxisType.y);
}
So, Why is the position returning a random position. It should not change at all, Because it's not moving...
Answer by Kruga · Aug 06, 2010 at 05:48 AM
I worked I was creating spheres and other object within the script. I assumed that the transform of the script would also be pointing at the sphere, or what ever object I had 'created' in the script. Which dose not seem to be the case. So instead of this :this.Transform = newPosition
it should have been sphere.Transform
. It's a little confusing, but seems to have corrected the problem...
The script seems to move up and down the world area. but the object created with in that script, is the correct position that you are looking for, and does not move.
Regards.