• 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 DanjelRicci · Feb 01, 2010 at 10:22 AM · collisionphysicsrigidbodyvehicle

Smoothing Rigidbody movement over a bumpy track

I have a Rigidbody spaceship running on a very deformed race track (like a rollercoaster). The control happens only applying a force to the Rigidbody, so I don't use wheel-like controls. The ship runs sticked to the track by moving constantly down its local Y axis, just like being attracted by a magnet, while being affected by gravity if it jumps out of the road.

Since the track is quite bumpy in certain slopes and turnings, I easily lose the control of the vehicle, because it bumps too much... Is there any way to smooth the collision between the vehicle and the track?

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 fran pugh · Feb 23, 2010 at 12:24 AM 0
Share

I feel your pain man, am trying to do something similar.. did you ever fugure it out?

2 Replies

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

Answer by duck · Feb 01, 2010 at 11:27 AM

Well first I'm going to mention "Rigidbody.interpolation" since this might sound like the obvious solution. You can switch this on, and it has the effect of smoothing out the movement of the physics object in question slightly, but in your case I don't think this is really going to help much, since it sounds like the bumps are at a larger scale, whereas this function is designed to smooth out the discrepencies which arise from the physics steps not being at an exactly steady rate.

I think perhaps what might be a better solution might be to split the "collision" and "visible" parts into two seprate pieces, and use a custom script to interpolate the visible object towards the collision object. I think you should have two GameObjects:

  1. Has rigidbody & collider, but no mesh renderer. This bumps over the track as you currently are doing, but is invisible.
  2. Has no rigidbody or collider. It just has the mesh renderer displaying the ship.

Let's call these gameobjects "Ship Physics" and "Ship Visible".

The 2nd object (Ship Visible) must not be parented to the first. Instead, it will follow the Ship Collider's movement by interpolating towards its position using this script. Create a new C# script, which should contain the following:

using UnityEngine; using System.Collections;

public class InterpolateToTarget : MonoBehaviour {

 public Transform target;
 public float xInterpolation = 5;
 public float yInterpolation = 5;
 public float zInterpolation = 5;
 public float rotationInterpolation = 5;

 void Update () {
     Vector3 localPos = target.InverseTransformPoint(transform.position);
     localPos.x -= (localPos.x * xInterpolation * Time.deltaTime);
     localPos.y -= (localPos.y * yInterpolation * Time.deltaTime);
     localPos.z -= (localPos.z * zInterpolation * Time.deltaTime);
     transform.rotation = Quaternion.Slerp(transform.rotation, target.rotation, rotationInterpolation * Time.deltaTime);
     transform.position = target.TransformPoint(localPos);
 }

}

Place this script on the "Ship Visible" gameobject. Then (with "Ship Visible" still selected) drag a reference from the "Ship Physics" gameobject into the 'target' variable in the inspector.

Finally, you probably want to set it so that the interpolation along its own local Z axis is much faster than the others, since this is the forward direction of the ship, so change the value for "Z Interpolation" to somethin much higher, like 100.

Give it a try and see what happens. You might find that you want to tweak the settings to tighten or loosen the interpolation, but it should help smooth out the motion of the spaceship.

Comment
Add comment · Show 2 · 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 DanjelRicci · Feb 01, 2010 at 07:31 PM 0
Share

Thanks a lot for your answer! Sorry, I forgot to say that I have already used Interpolation, but it didn't help much... Your solution is exactly what I though to do, it's a great way to smoothly render the vehicle. But there is a problem... The invisible Gameobject still hit all the bumps, so, in the worst case, you will see the ship jumping away with no reason... The best thing would be something like a function that smooths the collision map of the track. Anyway thank you very much for the help! :D

avatar image TriplePAF · Dec 09, 2010 at 09:18 PM 0
Share

It solved my problem completely with the rigidbody.$$anonymous$$ovePosition function. I can now enable the rigidbody interpolation settings without that my air vehicle starts to jerk.

avatar image
0
Best Answer

Answer by efge · Feb 01, 2010 at 10:53 AM

You should enable "Smooth Sphere Collisions" on the mesh collider component of your track. It smoothes the normals of the collision mesh.

Another try could be using different meshes for rendering and collision. The collision mesh should be as smooth as possible, but should contain geometry only in driveable areas.

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 DanjelRicci · Feb 01, 2010 at 07:34 PM 0
Share

Thanks for the help! I already used the Smooth Sphere Collision, but without noticeable results. Also, I know that render and collision mesh should be two different meshes. ;)

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

How do i get OnTriggerStay2D to work? 1 Answer

Limiting rigidbody physics influence on another rigidbody 0 Answers

Preventing objects from intersecting with minimal physics 3 Answers

Is there a rigidbody character controller 3rd person that can handel stairs (steps)? 1 Answer

How do I use rigidbody's collision detection modes? 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