• 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 jjesh · Dec 01, 2014 at 08:33 PM · movementrigidbodytimespeedup

When I use rigidbody.Moveposition, the object doesn't move accurately.

I've been using rigidbody.Moveposition for one of the objects in my game. It moves up for a set number of seconds, then moves back down for the same number of seconds, at the same speed. However, the object doesn't always move correctly. Sometimes it'll move higher than it should, but then move the right distance down, or vice versa. How can I make the movement more exact? This is the snippet of code I'm using to make it move:

     if(spinDirection == "up")
     
     {
     
         rigidbody.MovePosition(rigidbody.position + Vector3(0,30,0) * Time.deltaTime);
     
         }
     
     else if(spinDirection == "down")
     
     {
     rigidbody.MovePosition(rigidbody.position + Vector3(0,-30,0) * Time.deltaTime);
 
 }








Comment
Add comment
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

1 Reply

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

Answer by jenci1990 · Dec 01, 2014 at 08:47 PM

Use in FixedUpdate() not in Update(), and change "Time.deltaTime" to "Time.fixedDeltaTime".

Comment
Add comment · Show 2 · 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 jjesh · Dec 01, 2014 at 09:45 PM 0
Share

Thanks, that seems to have worked! What's so different about it though that it makes it work?

avatar image jenci1990 · Dec 01, 2014 at 10:16 PM 0
Share

The FixedUpdate called every (default) 0.02 seconds, but the Update called every frame, it's independent of time. Read it: http://answers.unity3d.com/questions/10993/whats-the-difference-between-update-and-fixedupdat.html

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

26 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 avatar image avatar image avatar image avatar image

Related Questions

Pushing rigidbodies around 1 Answer

Time.deltaTime problems? 1 Answer

Increasing speed for a few seconds 2 Answers

Player acts differently if not selected in the inspector 2 Answers

Change movement speed based on rotation 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges