Hello. I am not sure where to post this, so sorry if I am posting in the wrong section. Also, I really appreciate your help.
So, I have two Vector3 points, as shown in the picture - point A (actually, this is my camera) and point B (the point what camera.transform is looking at, so it’s always in the center of the screen, it’s actually an empty object in the editor). Now I have a problem - I am making a strategy game with moving and rotating camera, so I constantly need to move and rotate it. When mooving it, I have a problem with along which axis should I move the camera? If I move it along the global axis, it would just go in a constant way, so when trying to move it forward, it would move to the global forward, which is not good. Mooving it along its local axis is a disaster, too. The camera is looking slightly down, so it would just move closer to its viewpoint. The decision I am thinking about is to find a C point which would lie on the imaginary line which is composed of the line between A and B points, if you lay it on the terrain (rotating it to fit the terrain and putting on the terrain without changing its direction). The question is how to find this C point and am I doing it in the wrong way?
I am quite new to Unity and am really grateful for any help of the community. Thank you in advance.
Cheers.
Thanks for your response. Sorry, if this is a stupid question, but how can I move (translate) along my own axis? Like I have two points A(x1,y1,z1) and B(x2,y2,z2). How can I use translate to force point A move towards point B (like eternally while pressing the button)? And how can I force point A to move left or right relative to the point B while pressing the needed button? Thanks again.
The vector AB’ (B’ minus A) represents a direction. If you add that direction to your position, you will translate along that vector. If you normalize the vector first, you can then control the speed at which you travel along that vector.
Yes, thank you very much, I worked it out already. Anyway, now there’s a different problem.
I move my camera with Vector3.SmoothDamp to smoothly move it towards my viewpoint. Of course, when the viewpoint moves without changing direction, it works well. But when it does change its direction, the Vector3.SmoothDamp changes direction of my camera not so smoothly. I think, when the destination direction changes, I should start moving the camera in that direction after performing a little curve move. But it’s very hard for me to figure out, how to do that. I know, you already helped me a lot, sorry if this is too much.
I spent a while building a custom camera controller. Then i needed a cutscene for a boss exploding, so i tried out cinemachine which worked great. Then i wanted to blend between the two, and found this was tricky. But i also found that cinemachine was much better at the original control task than my custom camera controller.
So in the end i dropped the custom camera controller entirely and now use cinemachine for everything. Good luck!