• 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 Drury · Jan 14, 2015 at 05:19 PM · carjointfrictionwheel

2D anisotropic friction weirdness

You can't use friction direction 2 in 2D space yet [citation needed], so I use this one hack in combination with hingejoints and directionjoints to create a realistic top-down vehicle. For some reason though, after driving in a perfectly straight line for some time, the car spazzes out and just starts acting weird. Seems NOT to be an issue with joints not preventing wheels from rotating, but they might be responsible for glitching in combination with the script.

Here's my issue in detail.

http://www.reddit.com/r/Unity2D/comments/2segao/topdown_car_issues/

Here's my setup. (floatiness got set to 0 instantly after taking the screenshot, it was just a shot in the dark).

wheel.js

 #pragma strict
 
 var relativeVelocity : Vector3;
 var floatiness : float;
 
 function FixedUpdate () {
 relativeVelocity = transform.InverseTransformDirection(rigidbody2D.velocity);
 relativeVelocity.x *= floatiness;
 rigidbody2D.velocity = transform.TransformDirection(relativeVelocity);
 }

Here's what happens when I drive it forwards and backwards, just applying constant positive and negative force at transform.up of the car's GameObject.

alt text

Here's the state of joints after the ride. (perfectly intact and keeping the wheels nicely alligned)

alt text

Camera and crosshair don't have a rigidbody. They're parented to the car. Not much else to comment on.

At first I thought it was faulty joints at play, so I made them as rigid as possible, seems not to have solved the issue. When I floor it after the "after state," it goes sideways at random, thing is obviously broken even though joints are visibly intact.

So I think the issue has got to be the script, but I can't see anything wrong with it. Uses inversetransformposition to pick up relative velocity, kills the X but not really (so skidding is possible)(as I've said, floatiness is set to 0, so for all purposes, yes really), and yet ageenvenvejbvešťšľťľč+ľťž.

As for relativeVelocity, when I monitor it, X is constant and safe at 0 at all times, even though the car is obviously going sideways and wheels are obviously perfectly alligned even in motion.

When I drive slower/apply smaller force, it just takes longer to kick in. But the distance travelled at which it starts breaking is about constant.

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

1 Reply

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

Answer by Drury · Jan 14, 2015 at 08:20 PM

SOLVED:

Turns out the only thing responsible for all this weirdness is the one that I considered so insignificant I'd never considered mentioning it. Meant to apply force at the rear of the truck, applied it at the side instead. That being said, feel free to use the script underneath for friction direction simulation in your 2D games, be it top-down driving sims or sidescrolling dogfighters. It works perfectly.

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

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

2 People are following this question.

avatar image avatar image

Related Questions

Car "burns rubber" 1 Answer

2D Joint/Wheel Question 1 Answer

Square wheels 4 Answers

Internal collisions 1 Answer

Car wheels not stopping when I brake 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