c# - Translate camera to rotate left ('Q') and right ('E') -
i'm trying translate camera when press q , e want example when press 'q' camera translate left , let me give movement camera rotation, that tried this:
public class cameramove : monobehaviour { public gameobject player; //public variable store reference player game object private float movespeed; private vector3 offset; //private variable store offset distance between player , camera // use initialization void start () { //calculate , store offset value getting distance between player's position , camera's position. offset = transform.position - player.transform.position; } void update(){ if (input.getkey (keycode.q)) transform.position += vector3.up * movespeed * time.deltatime; else if (input.getkey (keycode.e)) transform.position += -vector3.up * movespeed * time.deltatime; } // lateupdate called after update each frame void lateupdate () { // set position of camera's transform same player's, offset calculated offset distance. transform.position = player.transform.position + offset; }
}
i had code living on lateupdate, follow player, want adapt code both, follow player , translate camera on button clicks, when press keys in case nothing happen, feel because late update transform, don't know how solve problem.
if want camera orbit around player(as stated in comment), in cameramove
's script update()
method:
if (input.getkey(keycode.q)) { transform.rotatearound(player.transform.position, player.transform.up, movespeed * time.deltatime); } else if (input.getkey(keycode.e)) { transform.rotatearound(player.transform.position, player.transform.up, -movespeed * time.deltatime); }
Comments
Post a Comment