How do I make a blueprint object move away from another object?

I have been trying to code in Blueprint for 5 or so hours now, with and without physics being applied (using VInterp for the non-physics attempt) to make a character object move away from another object, when the character overlaps it. “Away” meaning the direction from the sphere’s centre to in the direction that the player is currently in from the sphere’s centre. Help!


The most basic implementation would look something like this:

Image from Gyazo

You can see them getting stuck if blocked by something else, you did not include any details so not sure if this is a desired behaviour for you case.

You can, of course, implement this in the character and have it push objects away from itself instead.

For a physics based approach, it’d be enough to give them an impulse in the appropriate direction, much simpler solution.

Oh, so it’s GetUnitDirection. I swear, blueprint is so wrong in its wording logic that I will never find any of the necessary parts I need, I mean an “if” statement with a bool question is called “Branch” and it gave me issues just finding that out.

But if GetUnitDirection is what I needed, then what does VInterp do? And why couldn’t I use that to achieve this result? To my understanding VInterp would take the beginning location, the end location, and with positive speed value would decide a new vector location (towards the object), and with negative speed it should do the trick, no? It seemed to not do anything however, even at high numbers and I don’t understand why. May be I’m completely misunderstanding the use of it.

Your problem here is that you have actual programming experience. Not a problem, of course, but blueprint wording and api does introduce illogical and inconsistent wording in places, yes, I agree 100%.

In the example above I used a very ham-fisted approach and the objects simply slide in 2 axis away from the player in a linear fashion. vInterp would allow you to have them move in non-linear way:

Image from Gyazo

Notice smooth acceleration and arrival at target.

There’s also const version which is linear.

and with negative speed it should do
the trick, no?

No, it would just affect the interpolation speed, it would become negative - instantaneous / infinite.

Here’s a version that should make more sense:

Image from Gyazo

Image from Gyazo

Blueprint looks like this:

edited for clarity (I hope): Each sphere finds a direction from itself to the player, calculates a point along vector that is 400 units in the opposite direction (hence -400), and then interpolates its own movement until that location is reached.

You can of course do it the other way round:

So this should be somewhat closer to what you demonstrated in the original image.

Thank you Everynone!
As a beginner these animated examples and clear BP screenshots is an absolute life-saver. Please keep it up! :+1:

I got a simple way of doing this, it doesn’t take that much processing power and It stops the sphere from going through walls.

You can also make it go up and down if you connect Z in front of the “Get Rotation X Vector”, the code itself is complicated but it’s just cause I perfected it in a way that nothing can go wrong.

It rotates to where it’s going and it stops at walls, rn it goes away from anything but you can fix that with tags.

Move Away Code