Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 TheokieZA · Aug 20, 2011 at 08:14 PM · physicsraycasthover

Jittery Movement

Hi everyone!

I have a "hover craft" that works almost as desired, except its a bit jittery :( When you go straight and slow down it's okay, but as soon as you turn and slow down the background looks jittery even at 600 fps+...

Here's my code so far.

 var desiredHeight = 1.0; 
 var spring = 100.0; 
 var damp = 10.0; 
 var SpeedMovement = 5.0;
 var turnSpeed = 5.0;
 var movDir : Vector3 = Vector3.zero;
 var rotDir : Vector3 = Vector3.zero;
 var attachedRigidbody : Rigidbody; 
 
 function Update() { 
     if(rigidbody.angularVelocity.magnitude > 2)
         rigidbody.angularVelocity = rigidbody.angularVelocity.normalized * 2;
 }
 //HoverCraft Hovering
 function FixedUpdate() { 
 var cam : Transform = Camera.main.transform;
 var hit : RaycastHit; 
 
 var up = Vector3.up; 
 
 if (Physics.Raycast(transform.position, -up, hit, 100.0)) { 
 // Force required to negate gravity 
 var neutralForce = rigidbody.mass * Physics.gravity * 0.2; 
 
 var yDifference = (hit.point.y + desiredHeight) - transform.position.y; 
 var addForce = yDifference * spring; 
 addForce -= rigidbody.GetPointVelocity(transform.position).y * damp; 
 
 rigidbody.AddForceAtPosition(neutralForce + addForce*up, transform.position); 
 
 rotDir.y = Input.GetAxis("Horizontal") * turnSpeed;
 movDir.z = Input.GetAxis("Vertical") * SpeedMovement;
 // Calculate the x-axis relative to the camera
 
 var cameraRelative : Vector3 = cam.TransformDirection (movDir);
 // Apply a force relative to the camera's axis
 rigidbody.AddForce (cameraRelative);
 rigidbody.AddTorque (rotDir);
 //transform.rotation = Quaternion.Euler(cameraRelativeRight);
 } 
 
 Debug.Log(rigidbody.angularVelocity.magnitude);
 
 }

Thanks,

Theokie

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 TheokieZA · Aug 21, 2011 at 01:53 PM 0
Share

It also does this when im moving, not just slowing down :(

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by DanMarionette · Aug 21, 2011 at 02:54 PM

I think this may be the same thing I ran into once. I found I was having this problem when I had a camera following a moving rigidbody. I had two scripts, one on the rigidbody and one on the camera. I found that I was having trouble because I was using FixedUpdate() to apply a force to the rigidbody. It is odd because I know that is what your supposed to use but as soon as I moved it into Update() it smoothed it all out. I tried having the camera static and, using FixedUpdate() the rigidbody does move smoothly. It only stutters when you are updating a cameras position based upon the rigidbody's position.

So the first thing I'd try here is to move your FixedUpdate() code into Update(). I know this goes against what you should do but, I would just give it a try first to see what happens. If anyone else knows what is actually going on here I would be interested to know also.

On another note I noticed you are also looking up the cameras transform in every FixedUpdate(). You should just look it up once in Awake() and store it in your cam variable.

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 maxus · Apr 13, 2014 at 05:15 PM 0
Share

I ran into this problem to - just to clarify, make sure your camera movement and your player movement commands are both in the same method, i.e. both in FixedUpdate (ideally), or both in Update().

avatar image
1

Answer by aldonaletto · Aug 21, 2011 at 03:42 PM

I tried this script and found no jittering. I childed the camera to the hovercraft and set its position to (0, 2, -10), what placed it above and behind, and had no trouble. I added MouseLook to it and again everything gone right.
Are you using some camera script? If so, maybe it's a problem of Update() x FixedUpdate() timing, as @DanMarionette suspected - but I think you will have more problems if all your code is moved to Update, because you need a stable sustain force. Maybe the other way around is better: move the camera script (if any) to FixedUpdate.

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 nicknasti · Aug 04, 2013 at 09:57 PM

DanMarionette, thanks so much. You solved my issue.

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

Hover Effect with more rays as turbines? 1 Answer

Hovercraft Physics Problems 1 Answer

Skateboard slope problem 0 Answers

Physics.Raycast (Cheapest Methods) 0 Answers

Hover spring in local gravity 0 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