0
\$\begingroup\$

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.

\$\endgroup\$

3 Answers 3

1
\$\begingroup\$

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

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

Gyroscope:
http://docs.unity3d.com/ScriptReference/Gyroscope.html
http://docs.unity3d.com/ScriptReference/Input-gyro.html

\$\endgroup\$
1
\$\begingroup\$

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
Vector3 eulerGyroAngles = /*your input reading code*/;
gameObject.transform.position = (eulerGyroAngles.y, eulerGyroAngles.x, 0) * (corresponding magnitude vector);
\$\endgroup\$
3
  • \$\begingroup\$ Why do you use eulerGyroAngles ? Why not just Quaternion \$\endgroup\$
    – Drukalo
    Dec 7, 2015 at 14:09
  • \$\begingroup\$ @Drukalo If you know how to deal with them, go ahead. I personally prefer euler angles. \$\endgroup\$ Dec 7, 2015 at 14:34
  • \$\begingroup\$ I mean i really don't know how to make object move with gyroscope like this youtube.com/watch?v=L4xuMh2rkJQ \$\endgroup\$
    – Drukalo
    Dec 7, 2015 at 16:40
0
\$\begingroup\$

Unity-Gyroscope-Parallax

There is a free plugin for gyroscope parallax effects, it can move object position and/or rotate object in space via gyroscope input data as gravity vector or as a movement in space direction.

Object movement in space based on gyroscope

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .