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.
the sphere scale 5:
the parent of camera attached script rotatechild:
this works 100% - tested :)
Comments
Post a Comment