c# - Make camera follow that can fly around a sphere at a constant height and speed -


i need make script can make maincamera fly around sphere @ constant height , speed. need write in c# , i'm kinda new that, need help.

so far have wrote script orbits around object, want control camera wasd.

this orbit-script far

public class cameraorbit : monobehaviour {     public gameobject target = null;       public bool orbity = false;      void start ()      {     }      void update ()      {         if (target != null)          {             transform.lookat(target.transform);             if(orbity)             {                 transform.rotatearound(target.transform.position, vector3.up, time.deltatime * 10);             }         }     } } 

you have 2 options how this:

option #1 way started

option #2: instead of rotating camera around sphere center, can make camera child node of node in sphere center , change euler angles of parent node:

using unityengine;  public class rotatechild : monobehaviour {    void update()    {       if( input.getkey( keycode.w ) )          transform.rotate( 1, 0, 0 );       if( input.getkey( keycode.s ) )          transform.rotate( -1, 0, 0 );       if( input.getkey( keycode.a ) )          transform.rotate( 0, -1, 0 );       if( input.getkey( keycode.d ) )          transform.rotate( 0, 1, 0 );    } } 

use on node in sphere center. make camera child of node.

enter image description here

the sphere scale 5:

enter image description here

the parent of camera attached script rotatechild:

enter image description here

this works 100% - tested :)


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -