- Home /
2d sprite bacground motion?
Hello I really could use some help with this and this will need some explaining!
On the iphone homescreen there is a picture and when the device is titled left, right, up, or down the image slightly moves with it and then stops once the device has gone to far. It shows more of the picture in either directions when it is titled that way and then returns back to normal once not moving.
How would I be able to accomplish this in unity?
Any help would be appreciated!
Answer by RussianBsack · May 19, 2016 at 03:04 PM
You'll need to use Unity's Gyroscope capabilities, Heres some links : http://docs.unity3d.com/ScriptReference/Input-gyro.html http://docs.unity3d.com/ScriptReference/Gyroscope.html
Depending on how much experience you've had, it will determine how well/easily you complete this. I'll explain how to do it as its the best way to learn, when i get home i'll add some code snippets.
Start by getting the input of the gyro and reversing it, then create a offset vector which will be your sprite transform, Create a clamp (Mathf.Clamp) - This will determine how much it will move, Then you create a smooth move function (possibly Vector3.MoveTowards), this will create that slow movement.
This is just a rough way of doing it which you will need to polish up!
Here is the code! https://gist.github.com/anonymous/22e450792a6272929b7ad52a85f752ea
Thank you! I do need some more explaining so the code snippet will help!!
Sorry dude, was a little busy with work. Add me on skype and I'll explain it to you there.
Skype - goldennoodles.
Have added you! and sent a message! @RussianBsack
Still haven't received anything, what's your user? i'll try to add you.
Your answer
Follow this Question
Related Questions
resizing spherecast radius over distance? 4 Answers
Isometric camera 2d or 3d 2 Answers
Close meshes render in 2D, but not 3D 0 Answers
2D looking 3D game 2 Answers
Convex Mesh Collider on Procedurally generated mesh does not conform.. 2 Answers