Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Vigeous · Jul 17, 2012 at 04:53 AM · physicsfixedupdatejitterridigbodycollosion

Trying to mix physics and direct movement without jitter

So here is the thing I am wanting to accomplish. I have a flying ship that I want to apply forces to and have bounce off various objects. If it flies by something and a wing clips the obstacle, I want it to go spining. If it gets hit by a small fast moving object, I want to lurch a little bit. The game is 3D, but takes place entirely on a 2D plane, so I don't want the ship to get bounced up or down.

Here is the tricky bit. I want to have the thing "bank", even though it doesn't make a lot of real physical sense (for design and artistic reasons, I want it to bank a little when it turns. If it is turning and hits or grazes an object, I still want it to bounce and spin around the Y axis (world), but I want to leave the rotation about the Z axis(local) unchaged. i.e. I wish to retain the "bank" amount.

I have tried a number of methods and none of them are really satisfying me.

My first approach was to constaint x and z rotation, apply torque to turn and then adjust the transform's rotation directly. This, however, gets a little jittery do to conflicting update times, motion methods and interpolation methods.

The most basic form looks like this

 public class CleanPhysicsShipController : MonoBehaviour 
 { 
  void Update () 
  {
  transform.rotation = Quaternion.Euler ( transform.rotation.eulerAngles.x, rigidbody.rotation.eulerAngles.y, Mathf.Sin( Time.time ) * -10f ); 
  }
  
  void FixedUpdate()
  { 
  if ( Input.GetKey( KeyCode.W ) )
  {
  rigidbody.AddForce (transform.forward * 2.0f , ForceMode.Impulse); 
  }
  if ( Input.GetKey( KeyCode.S ) )
  {
  rigidbody.AddForce (transform.forward * -2.0f , ForceMode.Impulse); 
  } 
  if ( Input.GetKey( KeyCode.D ) )
  {
  rigidbody.AddTorque( Vector3.up * 10.0f, ForceMode.Impulse ); 
  }
  if ( Input.GetKey( KeyCode.A ) )
  {
  rigidbody.AddTorque( Vector3.up * -10.0f , ForceMode.Impulse ); 
  } 
  } 
 }

If I just let it rock back and forth, it looks smooth, but when I try to turn with the keyboard, it starts looking a little twitchy (I have my camera directly childed to the object, so the object appears static on my screen, but the surroundings jitter). I have tried moving the "roll" line into FixedUpdate and using Time.fixedTime or other time values. I haven't found a combination or calls, times and orders that works yet.

I have also tried using AddTorque and AddRelativeTorque (with X and Z unconstrained) to accomplish the independent roll/bank, but the yaw torque and the bank torque compose into some random twist that I don't desire. I want local Z rotation and world Y rotation and nothing else.

I toyed around with various hinges but that seems to really complicate things. Especially if I do this with a lot of different objects that I need to maintain and iterate on.

Is there any way to manually update the rotation of a gameObject that has a rigidbody so that it somehow acts in harmony with the physics system? Hypothetically, my physics portion only affects Y ( due to constraints on the ridigbody ) and my direct portion only affects X and Z.

Thanks!

Edit: Forgot to mention.I have tried using all three interpolation methods. None makes the sin wave rolling smooth, but the yaw torque choppy. Interpolate makes the yaw torque smooth but the sin wave roll choppy. Extrapolate is just kind of worse.

Comment
Add comment · Show 1
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 Fattie · Aug 30, 2012 at 08:03 PM 0
Share

Could you please "TIC$$anonymous$$" an answer to keep the site tidy.

2 Replies

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

Answer by Fattie · Jul 17, 2012 at 08:55 AM

I was only able to read your title: "Trying to mix physics and direct movement without jitter"

The answer is, you'll have to get in to "combined rigs"

This is at the very heart of rigging and making physics in Today's Game Industry.

Unfortunately I was not able to read your question (I am dyslexic) (to long-form writing) (or any manuals) but generally you will have to enter the magic world of taking a kinematic body and attaching a physical body underneath it, and other similar combinations.

In a simple version, you might have a totally "normal" PhysX model that bounces around, OK?

But make inside that essentially you can think of it as "a sprite", just a static 3D model, which, YOU rotate by hand as a separate cognitive process. (Quite possibly, using some sort of input from the physics layer.)

Another very common thing is you'll have an invisible "go to" target that behaves exactly "normally" using physX like in a hello world program for Unity3D. But then your real object in fact is always hunting after that go-to target, and doing so with behaviour of it's own (perhaps maintaining spin or whatever).

I hope this general comment helps in some way!

You need to make a "combined" rig to achieve your aims!

What's that great line from Star Wars, you'll take a step in to a broader world...

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
0

Answer by Vigeous · Jul 17, 2012 at 11:26 AM

Well. Now I feel kinda dumb. I tried this sort of child-parent thing with hinges, but that was overcomplicating it.

Now I have

Anchor -rigidbody with x and z rotation locked and interpolation set to "Interpolate" -Script that adds forces

And childed to that: Ship -Collider -Script that directly messes with transform]

I was all worried that if I did this, the parent object wouldn't have the right collider, but I forgot colliders can exist anywhere in the object hierarchy.

<--Really dumb and really happy to have an answer.

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

6 People are following this question.

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

Related Questions

Physics + first person camera = jitter? 4 Answers

Rigidbody on a moving tile 1 Answer

Multiplayer jitter on client 0 Answers

Game not running properly on slow machines (low fps) 1 Answer

"Fast" fixed timestep 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