unity3d - Using Parallaxing for a 2D game in unity Understanding the Z axis -


i'm using parallaxing 2d game in unity , basically, i'm moving position of backgrounds on x axis whenever camera moves (the camera moves right or left following character). i'm having trouble understanding line means parallaxscales[i] = backgrounds[i].position.z * -1; doesn't z position have depth? mean when position.z * -1 or position.z * 5. not affecting actual depth of backgrounds ive been using in game (since moving left , right). mean. why use z axis?

using unityengine; using system.collections;  public class parallaxing : monobehaviour {   public transform [] backgrounds;     private float [] parallaxscales;    public float smoothing = 1f;        private transform cam;              private vector3 previouscampos;       void awake ()   {     cam = camera.main.transform;  }  void start ()  {     previouscampos = cam.position;     parallaxscales = new float[backgrounds.length];       (int = 0; < backgrounds.length; i++)       {         parallaxscales[i] = backgrounds[i].position.z * -1;      } }  void update ()  {      (int = 0; < backgrounds.length; i++)      {          float parallax = (previouscampos.x - cam.position.x) * parallaxscales[i];          float backgroundtargetposx = backgrounds[i].position.x + parallax;              vector3 backgroundtargetpos = new vector3 (backgroundtargetposx, backgrounds[i].position.y, backgrounds[i].position.z);           backgrounds[i].position = vector3.lerp (backgrounds[i].position, backgroundtargetpos, smoothing * time.deltatime);      }      previouscampos = cam.position;  } } 

this parallaxing class using z value of backgrounds control amount of parallax gets applied them. e.g. higher z more movements happens background when camera moves. using gameobjects z value control parallax convinient because allows see in editor how parallax applied each object, , doesn't require custom script added each object.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -