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 IBAI23 · Mar 08, 2014 at 03:36 PM · move an object

GameObject trembles when moving with setPosition

Hi! to everyone,

I'm making a prototype of a shoot'em up game.

I just have in the scene a sphere and I made a script to move it just in the x axis. this is the code for moving the sphere:

 using UnityEngine;
 using System.Collections;
 
   

  public class EnemyScript : MonoBehaviour{
     
     public void Update () 
         {
             transform.position+= new Vector3(5,0,0)*Time.deltaTime;    
         }
     
     }

The sphere moves, but it does like little jumps and trembles as it's moving

Anyone can helo?

Thank you and kind regards

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 fifthknotch · Mar 08, 2014 at 04:05 PM 0
Share

First, I would move this under FixedUpdate as Update is called every frame. So if your computer FPS spikes, the would move faster. FixedUpdate is called every fixed framerate frame. Otherwise, I do not see any trembling when i run your script.

avatar image stevethorne · Mar 13, 2014 at 01:25 PM 0
Share

Probably not a solution but you shouldn't set the position to move the object, use transform.Translate ins$$anonymous$$d.

avatar image IBAI23 · Mar 13, 2014 at 01:31 PM 0
Share

I also did that, and still the same, if I have 2 gameobjects both of them "jump" at the same frame...even they move at different speeds

Thanks!!!

avatar image stevethorne · Mar 13, 2014 at 01:35 PM 0
Share

Do they have rigidbodies attached to them? If so, are they set to $$anonymous$$inematic objects?

avatar image IBAI23 · Mar 13, 2014 at 01:40 PM 0
Share

One objects is with rigidbody and no kinematic, the other object is moved with translate and has no rigidbody

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by supernat · Mar 08, 2014 at 04:29 PM

If you are not limiting the frame rate, you could have very small frame times, down in the floating point error. Using FixedUpdate and removing the time.deltaTime from your equation (replace it with fixed time delta) is one way to correct it. Under normal circumstances though, you can safely use time.deltaTime which compensates for frame time variation, so technically I don't think your code is wrong in general, only if you expect high frame rates does it become problematic.

Add this to limit frame rate to see if indeed that is the cause. Application.targetFrameRate = 60

Comment
Add comment · Show 1 · 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 IBAI23 · Mar 13, 2014 at 01:23 PM 0
Share

I coded the movement in FixedUpdate, modify the framerate to 60 and even used forces to move the rigid body (impulse) and still got this nasty jumps...

Anyone?

avatar image
0

Answer by IBAI23 · Mar 09, 2014 at 03:18 PM

Thank you so much guys,

I changed it to FixedUpdate and still got that "mini jumps", I coded the frame rate limit to 60 and still got the jumos too. I don't know what to do :(

Thank you for the quick and good answers!!!! :-)

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

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

Multiple Cars not working 1 Answer

I made a better shader how do i fix[add _Shadow Strength]help???>Sorry that im asking for to much 1 Answer

Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers

Move Camera only along y and z axis, but not both? 1 Answer

UnityEngine.Input.GetMouseButton(1)) issue 1 Answer


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