# Gyroscope Parallax Effect In Unity

I want to make a parallax effect in Unity 3D with gyroscope like the one on this site: http://matthew.wagerfield.com/parallax/

I found an asset, but it is too expensive.

So I need a script which I can set to the GameObject, so it would move depending phone's gyroscope.

It's not so hard to find some sources from google;

Parallax effect (logic):
How do I implement parallax scrolling in 2D?

You are asking like "Gimme a script dammit!". Well, i can't give you a script. But i can tell you how to write your own.

Parallax effect basically means moving background objects slower than foreground ones to create a fake 3D (or depth) effect.

So if you have a vector that represents foregound velocity like:

//values and names are example
Vector3 foregroundVelocity = new Vector3(10,0,0);


Than you can use these vectors for background velocity (not limited to these):

//values and names are example
Vector3 backgroundVelocity = new Vector3(7,0,0);
Vector3 evenMoreBackgroundVelocity = new Vector3(5,0,0);
Vector3 farFarAwayVelocity = new Vector3(3,0,0);
Vector3 rightInFrontOfHorizonLineVelocity = new Vector3(1,0,0);


Then you can get gyro input from Unity's own Gyrpscope class, as @AhmetZambak mentioned, and just move your sprites (or gameObjects) according to magnitudes of corresponding angles, like:

//pseoudocode