Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Sospitas · Jul 17, 2014 at 02:31 PM · movementmobilemultidimensional array

GameObject Array Shifting - Mobile Inaccuracies

Hi guys,

So I have a grid of game objects stored as GameObject[ , ]. I am shifting half of the grid up/down (left half if left was pressed, right half if right was pressed) based on up/down key presses. This is all working fine on my computer as I am running it, but it doesn't work properly when I put the build on my iOS/Android devices. The movements will be off by an amount each time I shift the grid.

EDIT: Just realised I didn't explain how I am doing the movements: I have tried two ways:

1 - Using Vector3.lerp in a coroutine to move each block independently in a main game script.

     float startTime = Time.time;
     while(Time.time < startTime + timeToTake)
     {
         gob.transform.position = Vector3.Lerp (from, to, (Time.time - startTime)/timeToTake);
         yield return null;
     }
     gob.transform.position = to;

2 - Using Vector3.movetowards in an update loop running in a script on each object.

     CellData targetData = gobGrid[gridIndexX, j].GetComponent<CellData>();
     targetData.targetPosition = gobGrid[gridIndexX, j].transform.position - new Vector3(0, distanceToMove, 0);
     targetData.distance = distanceToMove;

Image for better explanation: alt text

The FPS doesn't drop below 30 when looping through the array and doing the movements.

Thanks,

Sospitas

Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Landern · Jul 17, 2014 at 02:36 PM 0
Share

So.. there isn't a single question in your post, also post your code, at least the relevant parts for heavens sake. There are any number of reasons why you are getting the behavior you're getting if your question is "why does it function differently on mobile then on my local computer". The CODE is the $$anonymous$$EY since it controls the view.

avatar image Sospitas · Jul 17, 2014 at 02:43 PM 0
Share

Sorry, forgot to actually include stuff cause I've been working all day. $$anonymous$$istakes happen. I've included it now

avatar image Landern · Jul 17, 2014 at 02:47 PM 0
Share

Thanks for including snippets, however, the values that you use to define the the positions are not posted in your code. variables like from, to, distanceTo$$anonymous$$ove... how these values are constructed are of the up most importance, include how you deter$$anonymous$$e the values.

avatar image Sospitas · Jul 17, 2014 at 02:54 PM 0
Share

I am so out of it right now. Sorry.

from = gobGrid[gridIndexX, j].transform.position; to = gobGrid[gridIndexX, j].transform.position + ( or - ) new Vector3(0, distanceTo$$anonymous$$ove, 0); (same as targetPosition in the second snippet). distanceTo$$anonymous$$ove = 2; (size in height of each grid object).

Number 1 is just a Coroutine that is run when an input is detected. The state is changed to its "movement" state so that inputs are no longer detected, and is only set back after the movements are finished.

Number 2 runs on each block/grid object. The CellData script that stores the targetPosition and the distance variables has an Update function that calls $$anonymous$$oveTowards ONLY if the game state is in the "movement" state using these variables and its current position.

avatar image Sospitas · Jul 18, 2014 at 10:16 AM 0
Share

After looking some more into this, I removed the Lerp, and just had the objects update to their target positions instantly. This removed the problem of the inaccurate movement, but it obviously doesn't look nice when the objects just teleport.

The Lerp code is acting on ~230 objects at once when it runs, but the FPS never drops below 30 (and is only below the normal average of 60 for the short Lerp duration).

Is there something bad about using Lerp on iOS/Android? If so, is there a better alternative that I should be using?

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Simulate keyboard buttons to use Input.GetAxis ("Horizontal") 2 Answers

The game object penetrates the collision body when moving too fast 1 Answer

How to make responsive Touch inputs? 1 Answer

Problem in player movement using accelerometer input 0 Answers

Mobile select and move Object with offset 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges