x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

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!

alt text

Product Version: UE 4.22
Tags:
untitled.png (11.1 kB)
more ▼

asked Apr 30 '19 at 04:38 AM in Blueprint Scripting

avatar image

L11777
11 1 3 4

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

The most basic implementation would look something like this:

alt text

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.

capture.png (580.4 kB)
more ▼

answered Apr 30 '19 at 08:30 AM

avatar image

Everynone
14.7k 76 25 61

avatar image L11777 May 02 '19 at 02:59 AM

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.

avatar image Everynone May 02 '19 at 07:12 AM

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.

alt text

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:

alt text

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:

alt text

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

capture.png (153.3 kB)
cap2.png (245.4 kB)
cap3.png (89.5 kB)
(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question