How to Focus on Object in Game

Hi,

I am following this video to achieve the functionality that when I press a key, the camera can focus on the selected actor.

But I meet a problem when I follow this tutorial. I am writing these codes in the spectator blueprint. When I press the key, the spectator will go to the location of the selected actor which means inside the actor. I tried some way to calculate the distance between camera and actor or divide the location but none of them works.

I want to achieve the focus functionality like the one in the editor, press F, and close to the actor. Here is my code.

Thanks for your help.

I figure out a way to fix this.

I calculate the distance between the camera and the hit actor’s location. And then compare the distance with a certain amount so the camera will stop before that value which will not go into the select actor.

Not perfect though, I will upload any improvements in the future if I get any.

1 Like