Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 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
0
Question by siddharth3322 · Feb 01, 2019 at 11:49 AM · physicsrigidbody3dforceangularvelocity

Throw car out of the circuit, based on its facing direction using physics

I was working on Car Wars game so I require to throw the car which crosses circuit boundary.

The following image depicts my point clearly: alt text Now as per my programming setup, I require to throw my car through force/velocity manually applied and I want to flip the car in the car throwing direction.

I have tried myself about this but didn't able to get the desired result.

  myRigidbody.AddForce(transform.forward * 80f);
 
             Vector3 currentRotation = transform.eulerAngles.normalized;
             myRigidbody.angularVelocity = new Vector3(currentRotation.x * Random.Range(10f, 40f), Random.Range(10f, 20f), currentRotation.z * Random.Range(10f, 20f));

Now share your side suggestion regarding this, I want to give force and angular velocity manually based on side of the circuit car diving.

throwing-cars-from-track-1.png (81.7 kB)
Comment
Add comment · Show 10
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 xxmariofer · Feb 01, 2019 at 12:09 PM 0
Share

hello, have you tried getting the vector from the car to the center of the circuit, and applying the force in that direction?

avatar image siddharth3322 xxmariofer · Feb 01, 2019 at 12:17 PM 0
Share

Can you able to provide me some code to test for this? I will check on the spot and reply back to you. $$anonymous$$aybe you are in the right direction...

avatar image xxmariofer siddharth3322 · Feb 01, 2019 at 01:10 PM 0
Share
 Vector3 direction = new Vector3(circuit.position - transform.position);

 myRigidbody.AddForce(direction * 80f);
 myRigidbody.angularVelocity = new Vector(direction * Random.Range(10f, 40f));
Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by JonPQ · Feb 01, 2019 at 05:04 PM

you might want to add force in the direction of the edge of the track's normal vector, not the forward vector of the car... Or at least use the car's velocity vector perhaps. but track normal might be more consistent ? the car may be driving sideways or backwards, or at a glancing angle... That is pretty easy to calculate... if in square center postion of track... force vector is just left or right... If in the end (curved sections) its just a vector from the center of the circle towards car's current position. (normalized)

And to make the car rotate... you probably don't need to alter the angular momentum... just apply your push force at a point above the center of gravity of the car, and you'll naturally get rotation also... try using the car's position or center of mass for target position, plus Vector3.up * heightOffset. Then apply the force there... using Rigidbody.AddForceAtPosition

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 siddharth3322 · Apr 13, 2019 at 12:35 PM 0
Share

@JonPQ thanks for your above answer - I started working again on this point today. Can you write the above answer more properly? if become possible then please add small code snippets.

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

207 People are following this question.

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

Related Questions

Shooting a cannonball. 6 Answers

Direction of rotation and ApplyForce 1 Answer

AddRelativeTorque not rotating 1 Answer

Simple colliding objects are updated a frame late. 0 Answers

AddRelativeTorque results in incorrect angular acceleration (Maybe centrifugal force affects) 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