- Home /
Camera to follow the mouse to move to create the point
Camera to follow the mouse to move to create the point, thank you~!
In the game window, you can create your own at some point generate a path. You can add a camera to follow the path。 This camera can generate different paths 。 Click the Generate button to see the different paths! thank you!!
var cube1 :Transform; var speed : float = 2;
function Update () {
var hit :RaycastHit;
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast (ray,hit,1000)) {
if(Input.GetMouseButtonDown(0)){
var cube2 =Instantiate(cube1,transform.position,Quaternion.identity);
cube2.transform.position=hit.point;
}
}
transform.position = Vector3.MoveTowards(transform.position, target, Time.deltaTime * speed);
transform.LookAt(target);
}
Xiaohe, I don't understand your question. Does something not work in the code you posted? If so, what line is it? What are you trying to do, and what is happening ins$$anonymous$$d of what you expect?
Okay, reading over this again, I think you want the camera to continuously look at hit.point. To do this, you need to get the relative position of hit.point (relative to the camera):
var relativePos : Vector3 = hit.point - Camera.main.transform.position;
var rotation : Quaternion = Quaternion.LookRotation(relativePos);
Camera.main.transform.rotation = rotation;
Here is the documentation: http://unity3d.com/support/documentation/ScriptReference/Quaternion.LookRotation.html
Your answer
Follow this Question
Related Questions
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Setting Scroll View Width GUILayout 1 Answer
Faux Gravity Prolem? #2 2 Answers
Array problem -3 Answers
GetComponentInChildren(Renderer).active wont work? 2 Answers