How to push an object in the direction you are facing by clicking on it?

I would like to create a set up where clicking on an object in the world pushes that object slowly forward in the direction I am facing (this is using first person camera).

What is the best way to push an object by clicking on it?

hey there,

your playercontroller has a RotationMatrix stored (Get Control Rotation), from this you can create a ForwardVektor, which is the Direction your Center is pointing, i assume they are normalized so the length of this vector is 1.

Knowing this you can translate your object in adding this Vektor to your objects Transformation with a multiplier (how far shall this object moves). Result: your object moves to the direction you look at.

I believe there were a node (Add Movement or something).

kind regards
Wallhalla

Thanks for the input.

I had trouble with this, because I was trying to do this in the BP for the object I wanted to push. Should all this scripting be in the player object?

Also, which node do I need to use to convert the rotation output of Get Control Location into a vector for the Add Force at Location node.

I’m pretty new at this, so any fine detail would be much appreciated.

hey there,

well its up to you doing it in controller or your object you want to push.

First the Vector for the direction you want to push:

Get Control Rotation (target PlayerController or Pawn)-> Output → Get Forward Vector → Save: Now you have the push direction aka the vector you look along.

for the rest: I will do a picture for you when im home again, in an hour or so…

just wait :wink:

oh i just found that, this should help you out:

https://docs.unrealengine.com/latest/INT/Gameplay/HowTo/UseRaycasts/Blueprints/index.html

Thanks for this. I’ll give it all a look and get back to you with how it went.