- Home /
move camera to clicked object
Hi All
I'm making an RTS type game, and I need to get my camera to hover over any object I click on. Does anyone know of any scripts that might be available for that already?
Right now I got something like this:
if (Input.GetMouseButtonDown(0)) {
Ray ray = camera.ScreenPointToRay(Input.mousePosition);
RaycastHit hitObject;
Vector3 target;
Vector3 myYVector;
if (Physics.Raycast(ray, out hitObject, 100))
{
myYVector = camera.transform.position;
target = hitObject.transform.position;
camera.transform.Translate(target.x, myYVector.y, target.z);
}
}
But all this does is move my camera to a location I don't understand, and worse, it gets closer to the object. I need the camera to stay in the same y position.
Comment
Your answer
Follow this Question
Related Questions
SmoothDamp bounce effect 0 Answers
RTS Mouse Click Movement 1 Answer
RTS game: Camera movement is wierd 2 Answers
3D RTS camera 3 Answers
RTS CAMERA C# 2 Answers