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.

starikcetin
5,3334 gold badges26 silver badges60 bronze badges
asked Dec 6, 2015 at 16:32
\$\endgroup\$

3 Answers 3

1
\$\begingroup\$
answered Dec 6, 2015 at 18:26
\$\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);
answered Dec 6, 2015 at 21:22
\$\endgroup\$
3
  • \$\begingroup\$ Why do you use eulerGyroAngles ? Why not just Quaternion \$\endgroup\$ Commented Dec 7, 2015 at 14:09
  • \$\begingroup\$ @Drukalo If you know how to deal with them, go ahead. I personally prefer euler angles. \$\endgroup\$ Commented 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\$ Commented 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

answered Jun 30, 2022 at 9:41
\$\endgroup\$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.