- Home /
move a child object to a specific xyz coordinates
hello i have a problem when trying to move my camera to a xyz coordinates relative to the parent object (3rd person controller) im using this class/script attached to the camera, and calling it's methods from another script with the xyz values.
using UnityEngine;
using System.Collections;
public class PosCam : MonoBehaviour {
public void chPos(Vector3 val)
{
this.transform.position = val;
//transform.position = val;
//gameObject.transform.position = val;
}
public void chPos(Vector3 val, float x, float y, float z)
{
this.transform.position = val;
//transform.position = val;
//gameObject.transform.position = val;
this.transform.Rotate(x, y, z);//no problem in this line for now
}
}
the problem is, no matter if i send 0,0,0 as the "val" value, this is sending the position of my camera to a crazy position like 500,-9,80 something like that. image with the hierarchy attached, my player seems like that
pd: im trying to move my camera for a "first person view" in some places.
any suggestion will be very appreciated. thanks for reading
Hey, first of all, don't overload your method, they are simply not doing the same with different parameters, then "transform.Rotate()" will not give you the results you are expecting. Use localEulerAngles ins$$anonymous$$d.
Ok, thanks for the help, i will use one method, but, i still have the problem trying to set a position on the camera....it keeps going to another place...so far from it's parent gameObject... :/
Answer by FortisVenaliter · May 16, 2015 at 03:08 PM
Try using transform.localPosition instead of transform.position.
Transform.position uses Scene Coordinates. Transform.localPosition uses coordinates local to the parent object.
So, setting Transform.localPosition to (0,0,0) will make it match the location of the parent.
Answer by TrainWrek · May 16, 2015 at 04:41 PM
Try using transform.localPosition
Too bad, this answer was stuck in the moderation queue for 4 hours ^^. So i gave you also a +1.
Your answer
Follow this Question
Related Questions
Camera Follow a Target, but not Centered on it 1 Answer
Camera follow players z axis 0 Answers
How to get the camera's size in world units 1 Answer
Rotate camera a set amount of degrees around Player 0 Answers
FPS cam for Roll -a-Ball like game 1 Answer