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"

Bringing a player pawn back to its previous position after hitting the killzone

I'm fairly new to the Unreal Engine, and I'm currently creating a mini golf game.

So far, the only real problem I've come across is creating a position reset in between strokes, so that if the ball goes into out of bounds it would go back to its position before shooting, instead of how I have it currently set up (using the killzone to reload the entire level).

I've tried creating an empty actor and getting it to move to the player pawn's position whenever the ball wasn't moving, so that I could save the position, but I couldn't get that to work unfortunately.

I'm assuming the solution is pretty simple, but I can't wrap my head around it for the life of me. If anyone's willing to help, it'd be much appreciated :)

Product Version: UE 4.20
more ▼

asked Oct 05 '18 at 12:11 PM in Blueprint Scripting

avatar image

1 1 1

avatar image ThompsonN13 Oct 05 '18 at 01:17 PM

hmmm i would think to have a series of volumes that represent the bounds of the green. then when the players ball overlaps the bounds actor you get the location, get forward vector, then calculate X number of units backward and save this new location as a variable. then when the ball is done moving you set the location to the variable you set previously.

avatar image Gl0bauxe Oct 05 '18 at 02:38 PM

I think my problem lies in how to reset the location of the ball to the location variable, I'm not sure how to do that with a player pawn. Thank you for your answer though :)

avatar image ThompsonN13 Oct 05 '18 at 03:15 PM

to set the location you literally use a set actor location node, its about as easy as it gets.

of course you would want to wait until the ball is stopped before setting its location. also this is for if you want the ball to be placed where it went out of bounds not to return it to its original location.

alt text

capture.png (130.2 kB)
(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

Save the location of the ball when you swing. reset to it when you go out of bounds. You can probably set this wherever you apply the swing force to your ball.

more ▼

answered Oct 05 '18 at 02:29 PM

avatar image

1.4k 1 14 17

avatar image HarryHighDef Oct 05 '18 at 02:30 PM

ThompsonsN13's solution will also work but it will reset the ball back onto the green from where it fell off not where you took the swing.

avatar image Gl0bauxe Oct 05 '18 at 02:35 PM

What node would you use to reset to it? I've tried something like this by spawning a plane wherever I take a swing and using a move component to node to move the ball back to the plane's location, but it wasn't working...

avatar image ThompsonN13 Oct 05 '18 at 03:29 PM

heres the basic setup if you wanted the ball to return the location where it was hit from. i did this in the level bp but you could easily do it in individual actors.

basically when you hit the ball you record its initial location in a variable, then when the ball goes out of bounds (i used a overlap volume) you just set the balls location. you would probably record the location in the ball bp in which case you would just need to drag off the cast return pin in search for the variable needed.

alt text

capture.png (189.1 kB)
avatar image Gl0bauxe Oct 05 '18 at 07:39 PM

Hey, thanks so much for your answer! The only tiny hiccup I'm seeing at the moment is that I'm trying to do all of this into my ball blueprint, but I can't call an onActorBeginOverlap for my trigger box in side of there. But, if I call it inside of the level blueprint, the Start Location doesn't have a target and fails to compile, and I don't know what to assign to it (see screenshot for what I mean)alt text

The first part works, as my print string is giving me world location of the ball. Thanks so much for your help, guys.

capture.png (83.6 kB)
avatar image ThompsonN13 Oct 05 '18 at 08:39 PM

If you are setting your variable for the start location in the ball bp then all you need to do is get that value from the ball actor. So drag off the as golf ball pin and connect it to the target on the get variable node ball location.

avatar image Gl0bauxe Oct 05 '18 at 08:41 PM

I already tried that, but it doesn't work. A print shows me that it is going through, but the location of the ball isn't actually changed. Would it be because it is a player pawn? I'm not really sure what's going on.

avatar image ThompsonN13 Oct 05 '18 at 11:46 PM

A print shows me that it is going through

shows what exactly?

if you have the reference right and its running through the cast without issue then the issue must lie where you are setting the location. this is of course assuming that you are getting the variable from the golf ball bp via the as golf ball pin.

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

I fixed it! The problem was that my golf ball wasn't the actual scene root. As soon as I put it there, the location reset worked as expected. Thank you very much for your help!!

more ▼

answered Oct 11 '18 at 12:36 AM

avatar image

1 1 1

(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