• 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 daymont87 · Jan 13, 2013 at 08:59 AM · aidirectionchangebump

Bump & bounce rigidbody

Hello everyone! I use this simple script for my AI car, i have one question, why i cant change direction AI car by bumping into it? When i try push AI car by my car - AI just flies up(instead bounce from my car - img below), then grounded and move on. It looks very unrealistic=( I try use this script from docs, and freeze Y position - it helps push it to the side, but not helps make realistic change AI direction. AI looks like tank, which no one can't move from his way, but not like a car!)

alt text

 function Awake ()
 {
     rigidbody.freezeRotation = true;
     rigidbody.useGravity = false;
     GetWaypoints () ;
 }
 function FixedUpdate ()
 {
     if (grounded)
     {
         NavigateTowardsWaypoint () ;
         //automove forward
         var autoMove : float  = speed*Time.deltaTime; 
            rigidbody.transform.Translate(Vector3.forward*autoMove );            
         
         var rotation : float = Input.GetAxis ("Horizontal") * rotationSpeed;
          rigidbody.transform.Rotate (0, inputSteer*2, 0); // inputSteer calculated by another function
      }
     // We apply gravity manually for more tuning control
     rigidbody.AddForce(Vector3 (0, -gravity * rigidbody.mass, 0));
     grounded = false;
 }


123.jpg (105.9 kB)
Comment
Add comment · Show 5
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 cdrandin · Jan 13, 2013 at 09:31 AM 0
Share

You could cheat a little by checking collsion between said valid objects then restrict the y axis, then not allowing it to jump. Then just apply some force opposite to which side of the object has been hit with collision.

avatar image daymont87 · Jan 13, 2013 at 09:45 AM 0
Share

Can you say how to apply some force opposite to which side of the object has been hit with collision?)

avatar image cdrandin · Jan 13, 2013 at 11:44 PM 0
Share

um I am having trouble finding something important on the docs, but you will need to check at collision flags to tell you where the collider was hit, which gives you can idea. So for instance is collider has been hit on the left side, have the impact go to the right, so a positive force, looking at it as left is negative and right is positive.

Sorry I am pressed for time, but you want to look more in collision or colliders in the docs looking for flags.

avatar image daymont87 · Jan 14, 2013 at 03:35 AM 0
Share

Thanks, i create additional trigger collider on the side of my car for checking collision, whell, it not perfect, but works anyway) I just thought, that maybe exist more simplier way to do this, without use additional colliders)

avatar image cdrandin · Jan 14, 2013 at 05:10 AM 0
Share

There is always a better way, we just need to find it. Simplest is to have multiple colliders for the sides and front/back. Even though it may not seem good it is simple.

0 Replies

· Add your reply
  • Sort: 

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

9 People are following this question.

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

Related Questions

See if targeted ship is above, under, left or right of the script ship 1 Answer

Weird issue when trying to find objects inside field of view using Vector3.angle,Issue with checking if object is within field of view using Vector3.angle 1 Answer

Character movement when I switch cameras. 0 Answers

Unity2D, How do i check which way a sprite is facing? 1 Answer

Question : Pong(ball to change direction) 3 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