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
1
Question by Naphier · Feb 24, 2015 at 07:27 AM · inputplayermobiledesktop

How to standardize player input for AddForce on mouse/finger cursor

Hello! I'm trying desperately to figure out how to standardize the amount of force we add to objects in our game.

The game works by an invisible cursor (controlled by the mouse or your finger) that pushes dots around toward goals. Every frame that the dot is within range of the cursor force is added to the dot depending on the delta (velocity) of the cursor's movement.

The cursor's "velocity" is clamped x/y between -1f and +1f. So it is basically normalized (we used clamp because we were loosing small movements when using normalize). The force added is multiplied by (Time.smoothDeltaTime * 60f) to normalize for frame rate.

The issue is that I can't figure out what the difference is on each device that is requiring us to multiply the force added.

On Nexus 7 and Nexus 5 we're multiplying the force only by 80,000 In the Unity Editor we need to multiply the force by 500,000 In a Windows standalone build the force multiplier needs to be about 120,000

I have tried adjusting for frame rate - no change. I have tried to see the correlation between DPI or actual screen diagonal in inches and it doesn't correlate. For example:

  • The Nexus 7 is 7" with DPI of 216, 30FPS and requires a multiplier of 80,000

  • The Nexus 5 is 4.95" with DPI of 445, 60FPS and multiplier is also 80,000

  • The Unity Editor window size is 10.5", DPI 96, around 90FPS needs 500,000 multiplier

  • Unity Windows standalone window size is 8.5", DPI also 96, around 90FPS needs 120,000 multilpier

The code is basically like this: FixedUpdate() determine change in mouse position since last frame, clamp to -1,1 -> this is used as velocity

OnTriggerEnter2D/OnTriggerStay2D() addForce impulse to each dot depending on it's distance from the mouse point with the following calculation:

 Vector2 force = mouseVel * forceMulti * ratio * 1f / (Time.deltaTime * 60f);

ratio = distance from center
mouseVel = mouse velocity as explained above
forceMulti = the multiplier I'm trying to figure out how to standardize
1f / (Time.deltaTime * 60f) = my attempt to adjust for framerate because it seems that the higher the framerate the more force that needs to be added.

So... I have been trying all sorts of different things with little to no success. I'm now trying to determine the force multiplier in relation to the physical screen size based on the DPI and the screen's diagonal, but the relationship seems to be exponential which doesn't make sense.

I posted code before, but no one would help. I'll post code again if necessary, but I feel this can be discussed without it and my code is currently a mess from trying so many different things.

Please help! Thanks!!

EDIT: A short video of the game can be seen here: http://naplandgames.com/images/forum_posts/gravitone_short.avi

Comment
Add comment · Show 4
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 yashpal · Feb 25, 2015 at 09:02 AM 0
Share

@Naphier , This might helps you. setting fame rate might solve your problem.

avatar image Naphier · Feb 25, 2015 at 06:25 PM 0
Share

Thanks. That's one of the first things I tried. The issue is not framerate dependent. I've ruled that out with fixing the framerate with Application.targetFrameRate and setting vSync skip to 2. Both yielded a fairly solid 30FPS and still on Windows the editor is much more sensitive than an actual build. I've also now rewritten everything to exclude as much outside influence as possible. I use my own calculations for detecting distance and "collision" ins$$anonymous$$d of Unity's collision events, everything is now in FixedUpdate and I'm using impulse mode on the force added to the objects. Still wonky in windows, but it seems to be much better on mobile. Very confusing.

avatar image yashpal · Feb 27, 2015 at 04:56 AM 0
Share

hello @Naphier, I have one idea about your problem. You use your code inside FixedUpdate, so you use time.deltaTime.

Just put your code inside InvokeRepeating. and call invoke repeating at 0.03 sec(30 FPS). and don't use time.deltaTime. So it approx same time for every platform.

NOTE :- I think it's not best way to do this. And it might be not good for performance also. but Just try it out and tell me is it worked?

avatar image Naphier · Feb 27, 2015 at 05:10 AM 0
Share

I don't think InvokeRepeating is a good idea as it needs to be high performance and that's going to be a lot of calls to it. But maybe it would be O$$anonymous$$. I'm not planning to try it as it seems pretty good now.

I think that there were just too many factors and the velocity of the mouse/finger was probably the biggest problem. Since a large movement on a 5" device is medium movement on a 7" device.

I'm dealing with integrating a bunch of plugins at the moment and they're breaking other plugins so I am only co$$anonymous$$g back to this if I find issues again.

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

20 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

Related Questions

Detect if running on mobile vs desktop 2 Answers

TouchInput doesn't not exist in current content 0 Answers

does getmousebuttondown counts as physicaly clicking (for mobile games)? 1 Answer

Falling Character needs its position reset after swipe 1 Answer

Why won't my object activate? 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