• 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 Asle · Mar 27, 2010 at 06:04 PM · gameobjectshaking

My objects keep on shaking

Hi

I am pretty new to Unity.

I am making a wall of cubes, I spread the cubes in a room and let them find their appropriate place in the wall. The cubes have colliders, they are affected by physics until they are a few units away from the wall where I turn on Kinematrics to be able to put them where they are supposed to go in the wall.

When they are in their position they keep on shaking lightly, even if they don't have any other cubes around them, I have tried a lot of different ways to make them stop but it seems nothing is working.

function Awake(){ main=GameObject.Find("Main"); script=main.GetComponent("initmovecube"); script.x=script.x+1; x=script.x; y=script.y; z=script.z; lessz=script.z-2; cubenumber=name.Substring(0, name.Length - 7); script.cubeint=parseInt(cubenumber); Debug.Log(script.x+" "+x+" "+y+" "+z); if (x==100) { script.y=script.y+1; y=script.y; script.line=script.line+1; }

} pos=Vector3(x,y,z); function Update () { if(transform.position!=pos) { transform.LookAt(pos); transform.Translate(Vector3.forward*Time.deltaTime); if (Input.GetKey(KeyCode.Q)){ Debug.Log("Key pressed."); rigidbody.velocity=Vector3(0,0,0); } } if (transform.position.z>=lessz) { //Debug.Log("Cube nr: "+name.Substring(0, name.Length - 7)+" is on spot."); gameObject.rigidbody.isKinematic = true; transform.eulerAngles=Vector3(0,0,0); transform.rotation=Quaternion.identity; if (transform.position.y<pos.y ) { } } if(transform.position==pos) { gameObject.rigidbody.isKinematic = false; rigidbody.velocity=Vector3(0,0,0); if (rigidbody.IsSleeping()==false){ rigidbody.Sleep(); }

}

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

3 Replies

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

Answer by e-bonneville · Mar 27, 2010 at 06:25 PM

Like Eric said, (if transform.position == pos) is probably causing your problem, so try making it an integer. However, that may not be accurate enough for your purposes, and why not just set the position directly? You might also consider when it gets close to the correct position, deleting it and instantiating a kinematic cube in its place. It's worked for me multiple times when trying to make something kinematic and it continues behaving strangely.

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

Answer by Eric5h5 · Mar 27, 2010 at 06:16 PM

I think the main problem is you have things like "if (transform.position==pos)", but the position will never be exactly equal to pos, because of framerate variance and floating point imprecision. I don't quite understand what you're trying to do, but it seems like it would be much simpler just to set the position directly.

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 Asle · Mar 28, 2010 at 05:52 AM 0
Share

That is not exactly accurate, I ran a debug.log sentence within the if statement and it does become true after a while but it is random and even if it becomes true the cube keeps on shaking. I made one solution by activating a boolean within the statement and then run all code inside Update within an ifstatement based on that boolean.

avatar image
0

Answer by Asle · Mar 28, 2010 at 12:13 PM

this is the way I solved the problem:

function Update () {
  if (inpos==false){
    ...
    dist=Vector3.Distance(pos, transform.position);
    if(dist<0.1) {
      transform.position=pos;
      inpos=true;
    }
  }
}

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

how can my gameobject stop shaking? 1 Answer

using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers

GameObject on top of GUI 3 Answers

Reinitialize prefab 0 Answers

ReActivate object with null movement ?? 2 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