Download

Move object towards player?

Hey everyone.

I am trying to make a triggerbox and on overlap with this triggerbox I am trying to make an object which is set to movable move only slightly towards the player say 200 units.

the problem I seem to be facing is that I can not work out how to get the direction the player is in compared to the object and apply the move.

Can anyone help with this, I would post a BP of what I got so far but it would be a whole lotta nuttin.

i figured I would get the players location and the objects location but I do not know where to go from here or if this is even the correct approach.

Thanks,
Kriogenic.

get player location -> “Move Component To”?

This is some vector math you need to apply. If you’re not familiar with it, I would suggest to download the Content Examples project from the Marketplace and check out the Math Hall level. You could also read up on the matter here.

If you want to move an object in a certain direction, you need to get a vector that points in that direction. The vector that gives the direction from position A to position B is the difference between these positions: B-A. You’ll need to normalize this vector to get a unit vector (a vector with length 1). Now you can multiply this direction vector with a scalar (say 200).

The result will be a vector pointing in the right direction and having the correct length. So you just have to add it to your starting position (your object’s current location) to get the new position.

I hope this helps. Applying this to BP shouldn’t be too hard. There are nodes for each of these operations (vector subtraction, normalizing, multiplication). Let me know if you’re still stuck.

Thanks Bajee, I got it as soon as I read your post. I am not familiar with vector math but what you said makes perfect sense and the example in the Content Examples you mentioned looks like a great place to do some more digging into other areas of the maths functions. Thanks alot for the help.

By the way, you can use built-in Blueprint function GetDirectionVector. It does exactly what Bajee described!