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:
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… Smooth Camera Follow in Unity - Tutorial - YouTube
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.