Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to move camera automatically?

Discussion in 'Scripting' started by sotongqueen, Dec 26, 2008.

  1. sotongqueen

    sotongqueen

    Joined:
    Dec 15, 2008
    Posts:
    59
    Does anyone know how to move the camera automatically with first
    1) moving camera from ground and then elevate upwards to a certain position. 2) moving the camera forwards in a constant speed automatically ?

    i have tried using the following coding but i have fail to get my requirements. Does anybody know why?

    Code (csharp):
    1. var speed = 5.0;
    2. var terrainData : TerrainData;
    3. var parent : Transform;
    4. var moveSpeed : float = 1;
    5.  
    6.  
    7. function Update(){
    8.     var camera = camera.transform.localPosition;   
    9.  
    10.     //transform.Translate(Vector3.forward * Time.deltaTime*5); 
    11.    
    12.     if(camera.z < terrainData.size.z  camera.z > 0 ){
    13.  
    14.             transform.Translate(Vector3.up * (Time.deltaTime*5), Space.World);
    15.             transform.Translate(Vector3.foward * Time.deltaTime*5);    
    16.             }
    17.     else
    18.         {
    19.         transform.Translate(Vector3.zero,Space.World);
    20.         }
    21.  
    22. }
    Thanks in advance.

    :? :cry:
     
  2. sotongqueen

    sotongqueen

    Joined:
    Dec 15, 2008
    Posts:
    59
    To add on to this post, i have tired the following coding but i still does not get the output that i want. I am now able to move my camera from ground and elevate upwards to the certain level. However, when my camera reaches certain height, at the top, my camera fail to move forward. In fact, the camera is consistently moving upwards. What i want is to move my camera forward after it have reaches the top.

    Is there something wrong in my coding? Or do i need to set some condition to stop the movement when it reach the certain height ? Any idea or recommendation? Thanks in advance.

    Code (csharp):
    1.  
    2. var speed = 5.0;
    3. var terrainData : TerrainData;
    4. var parent : Transform;
    5. var moveSpeed : float = 1;
    6. //terrainData.size.x
    7. var smooth = 2.0;
    8. var tiltAngle = 30.0;
    9.  
    10.    
    11. function Update(){
    12.     var camera = camera.transform.localPosition;
    13.    
    14.     var rotateAroundYInput: float = Input.GetAxis("Horizontal");
    15.     var objectUp: Vector3 = transform.TransformDirection(Vector3.up);
    16.    
    17.  
    18. print ("Camera displays from " + camera + " to " + tiltY + " pixel");    
    19.    
    20.  
    21. // allow camera to move automatically forwards and upwards
    22.    
    23.     if(camera.z < terrainData.size.z  camera.z > 0 ){
    24.    
    25.             transform.Translate(Vector3.forward * Time.deltaTime*5);
    26.             transform.Translate(Vector3.up * (Time.deltaTime*5), Space.World);
    27.    
    28.     if(camera.y < terrainData.size.y  camera.y > 100){
    29.        
    30.             transform.Translate(Vector3.forward * Time.deltaTime*5);       
    31.             }
    32.         else
    33.         {
    34.             transform.Translate(Vector3.zero,Space.World);
    35.         }
    36.     }
    37.  
     
  3. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    The immediate problem I see given the description above and the code you've provided is that you want the camera to move "up" first (world's y-direction), yet your code checks against a z-position (not the world's up).

    I think that at this point it's wise to simplify things and start with the basics. As such, here's a script that will move the camera "up" (y-direction) until it reaches a specified trigger altitude, once at/above that altitude the camera will move forward:

    Code (csharp):
    1. function Update () {
    2.    
    3.   // Get the camera's current position
    4.   var tCameraPosn = transform.localPosition;
    5.    
    6.   // Set the trigger altitude (above this we'll move the camera forward)
    7.   var tTriggerAltitude = 20.0;
    8.    
    9.   // Check the camera's altitude (y-position) against the trigger altitude
    10.   if (tCameraPosn.y < tTriggerAltitude) {
    11.        
    12.     // Move the camera up
    13.     transform.Translate((Vector3.up * (Time.deltaTime * 5.0)), Space.World);
    14.        
    15.   } else {
    16.        
    17.     // Move the camera forward
    18.     transform.Translate((Vector3.forward * (Time.deltaTime * 5.0)));
    19.  
    20.   }
    21.  
    22. }
    Make a new scene and attach the above to your camera and see what happens. The script is very simple:

    - Get the camera's position
    - Set a trigger altitude (manually set to 20.0 for now)
    - Check the camera's y-position against that altitude
    - If we're below the trigger altitude then move the camera up
    - If we're above the trigger altitude then move the camera forward

    Done. Without worrying about the next steps (like dealing with your terrain or user input), does the above make sense?

    I don't generally like "giving" code as it's best for you to write it yourself (helps you understand it more), so if you do understand the above then try it again yourself, keeping things simple, and see how things work on your end.

    Once you have a handle in the above we can worry about checking the camera's position against a terrain as you seem interested in doing.
     
  4. simone007

    simone007

    Joined:
    Oct 30, 2008
    Posts:
    221
    its a pleasure to read such complete replies
     
  5. sotongqueen

    sotongqueen

    Joined:
    Dec 15, 2008
    Posts:
    59
    Thanks alot for the reply HiggyB. Now i get what i wanted. Thanks alot. =))
     
  6. sotongqueen

    sotongqueen

    Joined:
    Dec 15, 2008
    Posts:
    59
    To add on to this post, does anybody know how to rotate the camera in x-axis automatically without using the Mouse and keyboard control ?

    i have tried the following coding which i found from the scripting references in unity3d.

    Code (csharp):
    1.  
    2.  
    3. function Update(){
    4. transform.RotateAround( Vector3.zero, Vector3.up,20 * Time.deltaTime);
    5. }
    6.  
    7. i just want the camera to rotate in a 90 degree along the X-axis. shall i continue to edit in this script? Thanks in advance.
     
  7. VoxelBoy

    VoxelBoy

    Joined:
    Nov 7, 2008
    Posts:
    240
    Hey there,
    For questions like this, I'd suggest you first dig around the Script Reference, there is a lot to be found there :D

    But, I think this function should solve your problem:

    Transform.Rotate(x,y,z)

    Applies a rotation of eulerAngles.x degrees around the x axis, eulerAngles.y degrees around the y axis and eulerAngles.z degrees around the z axis.

    LINK: http://unity3d.com/support/documentation/ScriptReference/Transform.Rotate.html
     
  8. sharmoni

    sharmoni

    Joined:
    Dec 9, 2008
    Posts:
    14
    For my board game I've got an overhead camera rotating around the Y axis on a boom (empty GameObject) that is offset from the center of rotation. I want to be able to step rotate the boom in 60° increments via user input. I'm using the RotateAround code example from the Script Reference which works perfectly. I'm just having trouble coding the start/stop part of the interface.

    My first thought was to read the angle of the boom during each update to determine if it is evenly divisible by 60, but I can't figure out which variable holds that angle. Also, I'm not sure if that variable will consistently be an even integer.

    My next thought was to run a "for" loop for a second of time (the rate of rotation is 60° per second). But I can't see how to use Time as a counter. Also, I'm not sure if a loop based on time will give me exact positioning for each rotation or if I will get drift.

    The simplest would be to read the position of the boom and stop its rotation when it hits the correct angle, but I can't get the position numbers because when I rotate the boom in the Inspector, it rotates the boom object around its center instead of around the rotation point.

    I suspect this is rudimentary and I simply haven't read some part of the manual or reference (though I've been scouring them and the forum and the wiki for the past three days), but I'm running out of time on my trial and I'd like to prove to myself that I can successfully code scripts for Unity before I commit to purchasing it. Thanks for any help or thoughts about other methods.
     
  9. sotongqueen

    sotongqueen

    Joined:
    Dec 15, 2008
    Posts:
    59
    Thanks for the reply myraneal but i am sorry i think i have misinterpret it.

    Actually what i really wanted is that i need my camera to rotate in a clockwise direction around an arc slowly in the middle of my terrain. Am i able to continue to use the script as you have suggested as above? Thanks in advance.
     
  10. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    Yes, use either Transform.Rotate or Transform.RotateAround.


    First off, you want to rotate around the _X_ axis? Are you aware of what that will do? As you sit there, stick your right arm straight out, that is the x-axis, if you rotate around that you'll make the camera look up/down, is that what you're after? Or do you want to rotate around the _Y_ axis, so you'll orbit around a point on the terrain, as per your code above? I'm going to assume you want to rotate around the y-axis and not x ...

    The code you provided will rotate the camera continuously, what you need now is to use conditional statements (rotate until a specific condition is met, like "rotate until we've gone 90 degrees") and coroutines as they *really* help with animations like this.


    You can achieve this goal using code like this (untested forum code):

    Code (csharp):
    1. function DoRotateAroundAnimation (aPoint, aAxis, aAngle, aDuration) {
    2.  
    3.   // Determine the number of for loop steps needed (assume 30 fps for our loop)
    4.   var tSteps = Mathf.Ceil(aDuration * 30.0);
    5.  
    6.   // Determine the angle delta per step
    7.   var tAngle = aAngle / tSteps;
    8.  
    9.   // Do a for loop
    10.   for (var i = 1; i <= tSteps; i++) {
    11.  
    12.     // Do the rotate around step
    13.     transform.RotateAround (aPoint, aAxis, tAngle);
    14.    
    15.     // Yield for just a moment (assume 30 fps)
    16.     yield WaitForSeconds(0.03333);
    17.  
    18.   }
    19.  
    20. }
    When called the function above does a simple animation loop that won't lock up the rest of the Unity scripting engine:

    - The function determines some animation variables based on the information provided
    - A for loop is done:
    - Each step a small rotation is made
    - It then pauses a moment so the animation is done at 30fps

    The end result of the for loop will be the animation of your object (camera or whatever) as desired, you can offer different angles and durations (which can derive from a desired 'speed') as well as a point and an axis, and use the same function elsewhere. It could be called like this:

    Code (csharp):
    1. function Start () {
    2.  
    3.   // Trigger the rotate around animation
    4.   DoRotateAroundAnimation(Vector3.zero, Vector3.up, 90.0, 1.0);
    5.  
    6. }
    7.  
    8. function DoRotateAroundAnimation (...) {
    9.   ...
    10. }
    That would make the camera rotate 90-degress about the world origin and y-axis, over a period of 1 second. I'll leave it as an exercise for you to:

    - Learn and understand for loops, coroutines/yield andWaitForSeconds

    - Figure out how to apply the techniques to create a translation function that can be used in the earlier animation questions you asked

    :)
     
  11. sharmoni

    sharmoni

    Joined:
    Dec 9, 2008
    Posts:
    14
    Thanks so much, Tom. That was just what I needed, and very simple. I'm having to come up to speed very quickly with Javascript in the few weeks of the trial period and it's encouraging to see how much support there is on the forum.

    I like to learn backwards from working code, so program-specific code is very useful for understanding how to program in Unity. After many hours spent learning how Unity works it's very motivating and satisfying to have part of my game working.
     
  12. sotongqueen

    sotongqueen

    Joined:
    Dec 15, 2008
    Posts:
    59
    Hi HiggyB,

    Firstly, i would like to thanks you for your quick reply and allowing me to understand the camera axis better. Next, i have some doubt to clarify and i hope you don't mind.


    You are right, i am going to rotate my camera around the y-axis.

    May i ask for the code below is it showing the camera rotating only in 90 degree? Actually i wanted my camera to rotate in a circle from one degree to another degree, like rotating camera from 90 degree, 180 degree, 270 degree then to 360 degree. Can i still achieve that by following the script you given as an example below?


    Code (csharp):
    1.  
    2.  
    3. function DoRotateAroundAnimation (aPoint, aAxis, aAngle, aDuration) {
    4.  
    5.   // Determine the number of for loop steps needed (assume 30 fps for our loop)
    6.   var tSteps = Mathf.Ceil(aDuration * 30.0);
    7.  
    8.   // Determine the angle delta per step
    9.   var tAngle = aAngle / tSteps;
    10.  
    11.   // Do a for loop
    12.   for (var i = 1; i <= tSteps; i++) {
    13.  
    14.     // Do the rotate around step
    15.     transform.RotateAround (aPoint, aAxis, tAngle);
    16.    
    17.     // Yield for just a moment (assume 30 fps)
    18.     yield WaitForSeconds(0.03333);
    19.  
    20.   }
    21.  
    22. }
    23.  
    24.  
    25. Code:
    26. function Start () {
    27.  
    28.   // Trigger the rotate around animation
    29.   DoRotateAroundAnimation(Vector3.zero, Vector3.up, 90.0, 1.0);
    30.  
    31. }
    32.  
    33. function DoRotateAroundAnimation (...) {
    34.   ...
    35. }
    36.  
    However i have some doubt over the above coding. Firstly, may i ask what is "Mathf.Ceil" do ? i read from scripting references it stated that it will returns the smallest integer greater to or equal to f. However, i don't understand the statement "Mathf.Ceil(aDuration * 30.0); "

    Secondly, do i need to give a value myself for aPoint, aAxis, aAngle, aDuration inside the function DoRotateAroundAnimation()? I tried but it gave me errors.

    Lastly, i would like to ask why is there two similar function DoRotateAroundAnimation in the code? Is there any differences between the two? I am very very sorry if i ask alot of silly question because i am really a new beginner and are not very familar with programming terms in unity3d. i really hope you will understand and thanks so much for the help.


    [/code][/quote]
     
  13. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    Yes, the example call I made to my function (the one in the Start function) triggers a rotation of 90 degrees over a period of one second.


    You'll note that my function doesn't allow you to specify a starting point, it only lets you rotate from wherever you are now to the specified target (using the values provided when you call the function). If you want to change the numbers then go for it and you'll get the behavior you want. Do a series of rotations, do them all at once, whatever. :)


    The Ceil function does what it says, it takes a value and "rounds it up". Examples

    Mathf.Ceil(1.6) = 2
    Mathf.Ceil(2.1) = 3
    Mathf.Ceil(1.0) = 1

    In my case I have a duration (some amount of time, it might be 1.0 seconds, or it might be 3.923432 seconds), but from it I need an integer number of animation steps to perform and so I compute the number of steps required:

    steps required = duration * step-frame-rate
    -or-
    steps required = aDuration * 30.0

    But then to effectively use that in a loop I want an integer value, and one that ensures completion of the rotation so I round up instead of down.


    Do not modify the function, just call it like I did in my example Start function and specify the values you want. The DoRotateAroundAnimation function should work without modification on your end.


    But there aren't, there is only one DoRotateAroundAnimation function. In one case I provided just the function, in the second case I offered a more "complete" example showing how you might actually use the function.
     
  14. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    Just a quick note: The Ceil function in Unity is actually currently buggy, so that Mathf.Ceil(1.0) actually returns 2! It returns a value one too large for integers; for non-integers it works fine though.

    (The bug is reported long ago as case 32389 so I'm sure they're on it.)
     
  15. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    Thanks for the heads-up Rune, that bug is open but doesn't have any specific fix information just yet.
     
  16. sotongqueen

    sotongqueen

    Joined:
    Dec 15, 2008
    Posts:
    59
    Thanks for the clear explanation HiggyB. i will tried out the code and post up my doubt again. Thanks =))
     
  17. sotongqueen

    sotongqueen

    Joined:
    Dec 15, 2008
    Posts:
    59
    Oh well, i have tested and modify the above coding and realise i didn't manage to get the output that i want. Though everything work fine but i realise my camera actually went beyond my terrain. :(

    Hence, i tried to use the transform.Rotate method, it did work and allow my camera to rotate in a circle in the middle of the terrain. However, when i start to set boundary, my camera can only rotate halfway. I know something must be wrong with the boundary setting that i have created. However i really lost and unsure how can i really improvise on it and am i on the correct track. I hope someone may help.

    Code (csharp):
    1.  
    2.  
    3. if( camera.y >= 300){  
    4.                    
    5.           transform.Rotate(Vector3.up * (Time.deltaTime*speed), Space.World);
    6.          
    7.         if(  camera.x >=100  camera.z >=200 || camera.z < 400){
    8.            
    9.             transform.Rotate(Vector3.up * (Time.deltaTime*speed), Space.World);
    10.           }
    11.          
    12.         }      
    13.  
    14.  
    15.  
    Thanks in advance.[/code]
     
  18. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    What is the desired action when the camera somehow exceeds the terrain boundaries? You really need to make sure that your intended functional goal is clear as your code continues to confuse. By looking at the code above when you hit the boundary the camera "sits and spins" in place and I sense that's not what you're after.

    So, explain what you want to have happen when the camera exceeds the terrain boundaries and we'll go from there. Do you want it to rotate "up" until it's back over the terrain? Do you want it to "move in"? Other?
     
  19. sotongqueen

    sotongqueen

    Joined:
    Dec 15, 2008
    Posts:
    59
    i am sorry Higgyb. Firstly i guess i really have a big confusion between transform.rotate and transform.rotateAround.

    Alright maybe i start explaining what i am trying to do. Oh well i have road, streets and different type of block such as block A, B, C , D etc. on my terrain. Hence i need to use the code to manually rotate my camera around the terrain via it y-axis.

    This is the requirement which i need to do..

    1) if my camera.y position is greater or equal to 300( which is at block A position) , my camera will rotate around the terrain in a circle where block A is.

    However, i realize my camera will rotate out of the terrain if i am using the transform.RotateAround code.

    Hence, i modify the code to transform.Rotate and realize my rotation seem rotating too fast.

    I really not sure am i right in scripting this way in achieving my requirements or not.

    Code (csharp):
    1.  
    2. // To move the camera forward if the below condition is met such as camera.y position is greater than 230.
    3.  
    4.         if( camera.z < terrainData.size.z  camera.y > 230){
    5.            
    6.             transform.Translate(Vector3.forward * Time.deltaTime*25);
    7.            
    8.     //  }
    9.        
    10.     if(camera.z < terrainData.size.z  camera.y > 250 || camera.x > 100 ){
    11.        
    12.             DoRotateAnimation ( Vector3.up * (Time.deltaTime* 5), Space.World );
    13.            
    14.    
    15.         }
    16.  
    17.  
    18. function DoRotateAnimation (aAxis, Duration) {
    19.    
    20.  
    21. var tSpeed = Time.deltaTime * speed;
    22.  
    23. //======= I not very sure is the below for loop will allow my camera to keep moving in a circle.======
    24.  
    25. // Do a for loop
    26.  
    27. for ( var i = 0 ; i<= 100 ; i++) { // ==> is this for loop referring that my camera will keep rotating in a circle?
    28.  
    29. //Do the rotate around step
    30. transform.Rotate ( aAxis , Duration);
    31.  
    32. // Yield for just a moment (assume 30 fps)
    33.  
    34. yield WaitForSeconds(0.03333);
    35.     }
    36. }  
    37.  
    38.  
    Thanks in advance. Really sorry for the confusion and trouble.
     
  20. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    You still have not explained what you want, in words (not code!), to happen when the camera's motion takes it "outside" the terrain's x-z boundaries. Use words here and stop typing/thinking about code.


    The camera starts circling block X, that animation makes it move into an x-z position that's no longer over the terrain, what do you want to have happen with the camera?
     
  21. sotongqueen

    sotongqueen

    Joined:
    Dec 15, 2008
    Posts:
    59
    Ok, i am Sorry about that. As mention earlier i have road, street and many type of block (which i combine them and called them "map") inside my terrain.

    1) i will need to move my camera to the top of block C position in the Z axis(blue). Then when my camera reaches the block C position, it will start rotating via it Y axis (green) circuling block C in a clockwise rotation.

    2) When my camera started rotating, it should be rotating within block C area and not area that is beyond block C.

    3) As since my camera is position at the top, i would like to make my camera by tilting it downwards via it Z-axis, focusing on the area of block C while the camera is still continue to rotate.

    May i achieve that? Thanks.

    The image attach is viewing from a top view scene. The circle in yellow is representing the camera. Hence when it reaches the Block C position. it will rotate it in the clockwise rotation. The distance from the center point to the circular arc will be fixed. Now, i need my camera to rotate in a circular path when it reaches block C position.

    Really Thanks.
     

    Attached Files:

  22. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    Yes. When you get to your trigger point, use RotateAround to rotate around a particular point/axis as needed, see my sample function as an example. Beyond that, look up LookAt and add it to the animation function to keep the camera "looking" at the point around which you're rotating.

    Start with a *very*simple* test case and try it yourself (for example, put the camera in a position and simply have it rotate around a point using your own modified version of my script). If you get stuck then your next step is to upload a zipped copy of your project folder so we can see what you're attempting to do and where you might be stuck.

    And if you haven't done so already, please go through the tutorials we have on our website as they include these sorts of topics (not exactly these, but similar enough to prove helpful) and they'll let you build a solid base of general scripting knowledge you can use in Unity.


    Edit: and I am not going to ask a third time what you want to have happen in case the camera goes outside the block area, I've tried twice already with no success.
     
  23. sotongqueen

    sotongqueen

    Joined:
    Dec 15, 2008
    Posts:
    59
    Yes. Actually i tested and have modify my script and finally manage to make the camera rotate around the terrain. However, i don't want my camera to rotate around the terrain but circling around Block C. Hence i would like to ask, how can i apply a math algorithm in order for my camera to rotate in a circular path at block C .
    And my target object between my trigger point distance is fixed. I am struck with that. As i not sure how can i use a math algorithm to achieve that. Thanks
     
  24. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    I gave you a function (DoRotateAroundAnimation) as an example of how you can rotate around any arbitrary point, instead of using the terrain's position specify the "position" you have for block C, easy.

    More in general, go back to step 1 and make sure you have your head properly wrapped around RotateAround, it lets you rotate around a point (block C, block A, the world origin, whatever) and around an axis (the world's y-axis) for a specified angle, it's the core of what you need to use here and the rest is to provide nice smooth animated behavior instead of one big jump.


    Please rephrase, I don't get that second question.
     
  25. sotongqueen

    sotongqueen

    Joined:
    Dec 15, 2008
    Posts:
    59
    Hi HiggyB,

    really thanks for all your time and effort to answer each of my doubt and enquiries. You really make me learnt from those coding. Really really thanks. :D Now, I had manage to make my camera to rotate as what i want it to be. :)

    Right now, i am just facing with one problem which is to have my camera targeting on my game object while my camera is still rotating.

    I have tried transform.LookAt(target) coding and have choose my game object under the target portion in the inspector. I realize my code doesn't make my camera looking at the game object while rotating.

    Do you have any idea or advice for me to achieve that?

    Really thanks for all your help. =))
     
  26. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    So while rotating around block C, you want your camera to always look at some other target game object? If that's the case then you'll need to modify the DoRotateAroundAnimation function, essentially creating a "DoRotateAroundAnimationWhileLookingAtATarget" function. :D

    It shouldn't be too hard:

    - Add a new argument to the function call that is the target game object and inside the function, rotate around the block (A, C, whatever) and then look at the target:

    Code (csharp):
    1. function DoCameraAnimation (aPoint, aAxis, aAngle, aDuration, aLookTarget) {
    2.  
    3.   // Determine the number of for loop steps needed (assume 30 fps for our loop)
    4.   var tSteps = Mathf.Ceil(aDuration * 30.0);
    5.  
    6.   // Determine the angle delta per step
    7.   var tAngle = aAngle / tSteps;
    8.  
    9.   // Do a for loop
    10.   for (var i = 1; i <= tSteps; i++) {
    11.  
    12.     // Do the rotate around step
    13.     transform.RotateAround (aPoint, aAxis, tAngle);
    14.  
    15.     // Look at the target
    16.     transform.LookAt(aLookTarget.transform);
    17.    
    18.     // Yield for just a moment (assume 30 fps)
    19.     yield WaitForSeconds(0.03333);
    20.  
    21.   }
    22.  
    23. }
    - Change your call to that function so you now pass in a reference to the game object you want the camera to look at.


    Done.
     
  27. sotongqueen

    sotongqueen

    Joined:
    Dec 15, 2008
    Posts:
    59
    i tried modify my script but my camera seem moving downwards to the target object instead of rotating around and looking at my target object. Any idea what causes it?

    i don't know did i confused you. Actually i think i just need my camera Y-axis to look downwards at a particular position while my camera is still circulating around that particular position. As right now my camera position is straight while the camera is rotating. Hence i can't see my game object which is at the ground level.

    Thanks in advance.
     
  28. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    I have no idea what you've done in your code and my crystal ball isn't working so I can't "see" it from here. I can say that my script, provided as-is, works *perfectly*. My script allows you to rotate the camera around some point in space (ex: Block C), while simultaneously keeping the camera pointing at some other object of interest. Please test it as-is in a simple test project (make a plane, make a box, have the camera rotate around some point on that plane and point at the box, see it in action before trying modifications).
     
  29. sotongqueen

    sotongqueen

    Joined:
    Dec 15, 2008
    Posts:
    59
    You are right, i should test out using a simple project file. Thanks i will do it. Will post out my doubt if i have met up with any problems. Thank you so much. I know i have been giving you a lot of trouble. Really thanks a lot.
     
  30. sotongqueen

    sotongqueen

    Joined:
    Dec 15, 2008
    Posts:
    59
    Hi all,

    i had manage to make my camera to move automatically in my project. However i am still unable to make my camera to rotate around while targetting on my game object. I have tried it out on a simple project files but there are errors.

    I really need all of your helps. Anyway i have posted a new topic regarding this problem. Please kindly refer to the following post.

    http://forum.unity3d.com/viewtopic.php?t=17985

    Thanks in advance.[/url]
     
  31. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    Another thread on this same topic? I don't know that you needed to go that route and again I ask, have you used my script, as-is, in a simple project? Yes or no?

    If yes, did it work for you? If yes, why aren't you going to use my script? Restated, what else do you need that my script doesn't provide so we can offer guidance?

    If not then do that now please...


    Also:

    How so? Details, *please*.

    Really? What errors? Details, *please*.