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 zmeinaz · Jul 04, 2012 at 05:36 AM · physicseditoriosdifference

Why are the physics different between the editor and device (iOS)?

I have noticed a bit of a difference between the physics in the editor and the physics in the iOS device. Here is the code I am using to apply a force to a ball so that it moves in the direction of the touch:

     void FixedUpdate()
  {
  if (Input.touchCount > 0)
  {
  OnTap(Input.touches[Input.touchCount - 1].position); 
  }
  if (Input.GetButton("Fire1") == true)
  {
  OnTap(Input.mousePosition); 
  }
  }
  
  void OnTap(Vector2 pt)
  {
  Ray ray = Camera.main.ScreenPointToRay(pt);
  RaycastHit hit;
  if (Physics.Raycast(ray, out hit) )
  {
    Vector3 kForce = KickForce(hit.point); // calculate the force and kick!
    rigidbody.AddForce(kForce * forceMultiplier);//, ForceMode.Acceleration);
  }
  }
  
  Vector3 KickForce(Vector3 dest)
  {
    Vector3 dir = dest - transform.position;  // get target direction
  dir.y = 0; // Zero-ize the vertical aspect
     return  dir.normalized * rigidbody.mass;
  }

The ball moves much faster on the device as if FixedUpdate() is being called more often than in the editor. Does anyone know why this is happening?

Comment
Add comment · Show 3
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 AlucardJay · Jul 04, 2012 at 06:15 AM 0
Share

me : Possibly due to the time-step. iOS runs at 60 Hz, so you need to change the time-step in the editor.

In Unity, click Edit > Project Settings > Time

Now in the Inspector window, change 'Fixed Timestep' to 0.0166667

The editor should now run at the same framerate as the iOS device.

zmeinaz : I gave it a shot and it appears to exhibit the same behavior. Doesn't Fixed Timestep apply to both the device and the editor?

me : not sure then, shall convert my answer to a comment =]

avatar image whydoidoit · Jul 04, 2012 at 06:18 AM 0
Share

How is Fire1 mapped?

avatar image zmeinaz · Jul 04, 2012 at 06:23 AM 0
Share

As left mouse down. The idea is to apply the force while the left mouse button is held down (for editor) or while the player is touching the screen (device).

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by whydoidoit · Jul 04, 2012 at 06:25 AM

So your problem is, on the device, the code is running once for the touch and the touch is also triggering your Fire1 iteration. I suggest an else in front of your Fire1 test...

Comment
Add comment · Show 7 · Share
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 AlucardJay · Jul 04, 2012 at 06:31 AM 1
Share

well spotted (have to admit I didn't read that thoroughly). For editor controls and touch controls I usually use a configuration like this :

  // check if in Unity Editor or on Device
  if ( Application.isEditor || Application.isWebPlayer )
  {
      // $$anonymous$$ouse Inputs
      if ( Input.Get$$anonymous$$ouseButtonUp(0) )
      {
          // do stuff
      }
  }
  else
  {
      // TOUCH Inputs
      var count : int = Input.touchCount;
 
      // do stuff
  }
 
 

(if i have to edit another answer 'cos the script formatting is now stuffed thanks to UDN , I shall lose it .... )

EDIT : aaaarrrggghh !

avatar image whydoidoit · Jul 04, 2012 at 06:34 AM 0
Share

Hey it's totally screwed up my forum access too. If I Google something and it is a forum message - clicking on it just loses the link and takes me to the forum home :(

avatar image AlucardJay · Jul 04, 2012 at 06:42 AM 0
Share

same behaviour with forums here :S

avatar image zmeinaz · Jul 04, 2012 at 07:19 AM 0
Share

That was it! Thank you, I didn't realize that 'Fire1' is also triggered from a touch.

avatar image whydoidoit · Jul 04, 2012 at 07:20 AM 0
Share

Yeah - touch emulates mouse on the device...

Show more comments

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

8 People are following this question.

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

Related Questions

Difference Unity3 and Unity3+iOS 2 Answers

Objects that appear in the editor's game view do not appear in the game build 0 Answers

60FPS constant, but serious visual stutter - only on iOS 1 Answer

How to assign a joint's 'connected body'? 1 Answer

Why does Unity 2019.1 constantly (re)import things? 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