unity3d - Camera rotation within a prefab -


i trying create multiplayer game in unity3d using diablo camera system. wherever click on screen. system working fine in singleplayer did not need include camera in player prefab. facing problem camera rotation affected rotation of prefab parent. hierarchy looks this:

enter image description here

there script added camera looks this:

using unityengine; using system.collections;  public class maincameracomponent : monobehaviour {  public gameobject reaper; private vector3 offset;   void start () {     offset = transform.position - reaper.transform.position; }  // update called once per frame void lateupdate () {     transform.position = reaper.transform.position + offset; } } 

when run game camera stays behind character, while want stay @ same rotation. if order character walk north see back, if walk south wanted see front.

enter image description here enter image description here

notice how shadow changes, (thus rotation) face of model. tldr: want child camera ignore rotational change of parent , static. whilst letting camera position guided parent. far know seems impossible make networkmanager instantiate new player prefab , attach camera afterwards on same hierarchy level.

any appreciated.

however facing problem camera rotation affected rotation of prefab parent

that's because camera child of player whatever player/parent doing. camera should not under player. remove , make sure not child of player or other object. script should work or make camera follow player without making camera child of gameobject.

remove player = gameobject.find ("player"); lateupdate function. have done in start function, unnecessary in lateupdate function. gameobject.find ("player"); should never called directly lateupdate function. slow down game.

edit:

after reading comment, looks want instantiate player camera. can without making camera child of player.

your current setup:

  • player

    • model
    • projectile

      • projectile mesh
    • camera

so camera under player.

you new setup:

  • playerprefab

    • player

      • model
      • projectile
        • projectile mesh
    • camera (attach script in question this)

camera playerprefab instead of player. now, can instantiate playerprefab , move player script. don't know move script looks should attached player not playerprefab. playerprefab used hold can instantiated one. code in question should attached camera.


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -