Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 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 yahyaidrees · Dec 17, 2021 at 11:02 AM · carcar gamecar physicscar-tutorialcar race

how to rotate car to camera direction using wheel colliders.

I want to move and rotate car toward camera direction, which is orbiting my car, my car is moving through vertical and horizontal keys, and my camera is orbiting my car through swipe touch. my camera is following my car, but when I change my camera direction, the car is moving straight, I want my car to move and rotate towards camera direction when changing my camera direction.
Actually i want to make control like this: https://www.youtube.com/watch?v=jWCBw6YOPB4&ab_channel=SIBASANKARMURMU

Comment
Add comment · Show 2
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 metalted · Dec 17, 2021 at 01:02 PM 0
Share

What kind of game play is this? You say orbiting so im guessing its a 3D game, GTA-ish kinda camera and by swiping the screen, you can orbit the camera around the car.

If this is the case, you could subtract the cameras x-y position from the cars x-y position to get a direction vector from the camera to the car. By comparing this to cars forward vector, you can calculate the angle between the camera and the car. Depending on the angle, you could decide to steer left and right to align yourself with the camera, a.k.a. write some code to make the angle between the camera and the car as close to 0 as possible.

avatar image yahyaidrees metalted · Dec 17, 2021 at 03:08 PM 0
Share

thanks for your response, i will try these things, Actually i want to make something like this: https://www.youtube.com/watch?v=jWCBw6YOPB4&ab_channel=SIBASANKARMURMU

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by JonnyHilly · Dec 18, 2021 at 02:23 AM

This will be very tricky, due to needing to predict how much steering angle is required to turn smoothly towards a moving target of the camera without going past the current camera angle... and also taking into account any current input and change in the camera's facing direction. Most games would do it the other way around, have your swipe delta +-X control the steering position of the wheels, and then have the camera follow the car and look at the car's position. camera.transform.LookAt( car.position)... // or something similar...

there are existing unity scripts for smoothly following characters ( any object ) for example... https://www.youtube.com/watch?v=MFQhpwc6cKE

If you really want to try doing it the hard way.... start with the transform.forward vectors of both the camera and the car. zero out the Y component so the vectors are flat along the ground plane and normalize them. Now use crossproduct of the 2 vectors to determine the angle between the vectors ( how much you need to turn ) and use the cross ( vector ) product of the 2 vectors to determine which way to turn ( left or right ). but with this technique once you get the basic turn left/right working... you are likely to have a car that turns too far all the time and oscillates back and forth, searching for the correct angle. The math is tricky.

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

134 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

Related Questions

drift car using rigidbody 1 Answer

simple drift car movement 0 Answers

Destroyed car styled need for speed? 0 Answers

Shift gear with own RPM? Help please! 0 Answers

Car physics without wheel colliders? I've been trying for ages. 1 Answer


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