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 oquendo · Apr 20, 2011 at 10:03 AM · collisioncolliderdragjitter

Unwanted jittery behavior

I have the following code in a script for a 2D game in the XY plane

function FixedUpdate () { // Make sure we are absolutely always in the 2D plane and with the right rotation. transform.position.z = 0; transform.eulerAngles= Vector3 (270,0,0); }

function LateUpdate () { var realWorldPosition: Vector3 = Camera.main.ScreenToWorldPoint (Input.mousePosition); var gamePosition: Vector3 = Vector3(realWorldPosition.x, realWorldPosition.y,0); transform.position = gamePosition; }

function OnCollisionEnter (collision : Collision) { var forceDirection:Vector3 = -1*collision.contacts[0].normal; collision.rigidbody.AddForce (forceDirection * pushPower, ForceMode.Impulse); }

The GameObject this is attached to moves with the mouse and applies a force to any collider it encounters. The thing is, once a collision occurs, the attached gameobject becomes all jittery for a while. It then goes back to normal, but it's annoying.

I've set infinite linear and rotational drags to its rigidbody, but it doesn't work.

I have no idea how to solve this.

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

2 Replies

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

Answer by oquendo · Apr 21, 2011 at 10:10 AM

Apparently, the problem had to do with the calculation of the object's position and the code controlling the camera's position. They were both inside the LateUpdate function, but in different scripts. I moved them both to the same script, calculated the camera's position and THEN the object's, and it seems to work.

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 Fervent · Apr 20, 2011 at 08:54 PM

You are mixing Physics with transforms. You need to attach this object via a spring joint or something to a parent object that is moved via the mouse to avoid wacky behavior. set the parent object to kinematic. That will allow you to have a RidgidBody on an object while controlling it via transforms.

Avoid any transform modifications to a body under physics control.

transform.position.z = 0; transform.eulerAngles= Vector3 (270,0,0);

this is bad and can be accomplished via constraints on the RidgidBody instead.

Does this object HAVE to have a RidgidBody component? Since you are moving it with the mouse it doesn't sound like you need a RidgidBody attached, just a collider to test for collisions, In fact it sounds like you really need the collider to be a trigger instead and use OnTriggerEnter.

Comment
Add comment · Show 4 · 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 oquendo · Apr 21, 2011 at 08:19 AM 0
Share

O$$anonymous$$, that's useful, thanks. I'll check it out before giving a definite O$$anonymous$$.

avatar image oquendo · Apr 21, 2011 at 08:37 AM 0
Share

If there's no rigidbody attached, can I still access the collision information? I would need to use the normal to calculate the direction for the applied force. Also, if I have no Rigidbody, then I guess I need to keep the transform.position and transform.eulerAngles statements. Is that right?

avatar image oquendo · Apr 21, 2011 at 09:07 AM 0
Share

The jittery behavior seems unrelated to Physics, I removed the Rigidbody but the problem remains. I now think the problem is related to the lapse between the calculation of the object's position (var realWorldPosition: Vector3 = Camera.main.ScreenToWorldPoint (Input.mousePosition)) and the camera refreshment. Or something related. Any ideas?

avatar image oquendo · Apr 21, 2011 at 09:08 AM 0
Share

The problem gets worse when the object is moving fast, which seems to confirm my comment above...

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

No one has followed this question yet.

Related Questions

Objects with colliders going through walls and each other. 3 Answers

Collision with drag object 2 Answers

Ignore collision at high velocity. 1 Answer

Trouble with Physics.IgnoreCollision 0 Answers

Big issue with colliders 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