Download

Gravity Gun

I know I can get the actor to be set to the players location. That bit I have done. But how do it get it to follow the players view? When the actor teleports to the player it always teleports to the same place. Maybe some idea of how to make it lerp instead of teleporting? Cheers

Need to do it in the tick function so each frame it moves slowly towards the position.

Here’s an easy way to ease, obviously using the proper actor locations.



float speed = 2;
float distance = 200;
FVector SuckLocation = Camera->GetActorLocation() + Camera->GetForwardVector() * distance;
SetActorLocation(GetActorLocation() + (SuckLocation - GetActorLocation()) * DeltaTime * speed);

You could use a UPhysicsHandleComponent on your Player (or Gun)
The important functions are:

To grab in the distance you can Calculate the End Reach Point like Juice-Tin recommended.
And then use a LineTrace to that point to check if you the Gun is in range

[EDIT]
here is the Blueprinted Verasion. It is alomoast exactly transferable to C++
The only thing is that GrabComponent is deprecated and you should use the function I mentioned above:
Unreal Engine 4 - How to Grab and Drop Object (Blueprint Tutorial)