Announcement

Collapse
No announcement yet.

Making a respawn for my vehicle?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Making a respawn for my vehicle?

    Hey guys I'm new to unreal 4 and just going to say, it's really awesome and cool! ^^ So I have this college assignment to make a playable 3D game with some interaction, so I decided to do a time attack racing game, everything is going great; using the car blueprint project and managed to get car AI working thanks to a tutorial online. But I have one little thing I want to add in my game but I can't find any tutorials so I decided to post this to you guys to see if you could help me out with this. :3

    I basically want to make it so if my car crashes and falls on it's side/upside-down I could simply press a binded key to make it respawn at the same place it tipped over.

    Thanks ^^

    #2
    Hi Korey, and welcome to UE4! Have you checked out How to Respawn a Player in Blueprints from the documentation?

    Comment


      #3
      Ahh thank you!! How didn't I see this before xD

      Comment


        #4
        Okay new problem, I followed the guide and it doesn't work for me sadly, when I start the game and press R it just destroys my car and nothing happens after that.. Here's a few screenshots Click image for larger version

Name:	Sedan.png
Views:	1
Size:	369.1 KB
ID:	1079627 Click image for larger version

Name:	Sedan2.png
Views:	1
Size:	368.3 KB
ID:	1079628 Click image for larger version

Name:	Sedan3.png
Views:	1
Size:	350.5 KB
ID:	1079629

        Comment


          #5
          When you cast to the sedan in the GameMode, the object reference should be the character, not the controller. Basically, you are binding the OnDestroyed event to the Sedan, but are telling the controller to respawn, not the Sedan itself. Try changing that, and let me know if that fixes it.

          Click image for larger version

Name:	GHT3B_1.jpg
Views:	1
Size:	19.2 KB
ID:	1079638

          Comment


            #6
            Well I can't find "MyCharacter" or any character to be exact :S
            Sorry about this, I'm still new to all this.

            Comment


              #7
              LOL sorry about that, I just posted the example from the documentation. What I was trying to hint at was in your Game Mode (i.e. MyGame), from the "Cast To Sedan" node, change the "Object" pin connection from "Get Player Controller" to "Get Player Character". The easiest way to do this, is to just select and delete the "Get Player Controller" node, then drag off the "Object" pin and type "Get Player Character". I'm not at home, and don't have access to UE4 right now, but can upload a more accurate image if necessary.

              Comment


                #8
                Okay I just swapped the get player controller to get player character then I tested it, still nothing :/

                Comment


                  #9
                  AHA! Just had a light bulb moment

                  So... this gets a little tricksy. Since you are dealing with the Sedan BP as your Player Pawn (not a character based class, but pawn based), you need to cast to it's parent first to be able to talk to it directly. If you look up to the top-right corner of your Sedan BP, you will notice it says "Parent class: Wheeled Vehicle". This means that it not only is the Sedan, but it is derived from the Wheeled Vehicle class as well (which gives it physics and such). In order to go from the Game Mode to the Sedan, we need to get the pawn, cast it to the Wheeled Vehicle class, then recast to the Sedan.

                  Click image for larger version

Name:	CastToSedan.PNG
Views:	1
Size:	149.6 KB
ID:	1079667

                  Also, something fun to play around with during casting, is the "Cast Failed" pin. This lets us do something else if the cast ever fails on us. I added a "Print String" node, and typed in some information to see how far the casting was actually getting for quick & dirty debugging (there are much more elegant ways to debug, I'm just not there yet LOL).

                  The only issue I've run into so far, is that whenever I make it respawn the car, it will only do it completely one time. I'm not 100% sure why this is the case, but don't have much time to really look into it now, sorry. If you need further help though, I am willing to help and learn when/where I can.

                  Comment


                    #10
                    Aha! It works thank you ^^ And mine keeps repeating so that's a plus

                    So I have another question related to this, instead of respawning to the PlayerStart location is it possible to make something that whenever I hit respawn, it will take me to the closest place to respawn on the track instead of taking me all the way back to the start of the track, because as you see I'm making a time attack-ish game and my sedan tends to tip over abit if you're not careful.

                    Comment


                      #11
                      Sorry for the late response. I've been out of town in Federated Identity Management training, ugh!

                      ...is it possible to make something that whenever I hit respawn, it will take me to the closest place to respawn...
                      Yes, it most certainly is! You have a several ways to accomplish this. Just to name a few, you could make the vehicle respawn...
                      • in it's current position,
                      • in a set position,
                      • or at the location of another object.


                      Here's how you would make it respawn in-place (same facing, orientation, etc.)...
                      Click image for larger version

Name:	RespawnInPlace.PNG
Views:	1
Size:	94.5 KB
ID:	1079731

                      In short, what we've done is told the Sedan BP that when we press the F key, we are going to tell the Game Mode to set the Spawn Transform (where we get spawned) to the Actor's current Transform prior to it being destroyed. Then we destroy the actor, and the Game Mode respawns the pawn in the new set Transform.

                      Something to consider: if you are going to have your actor flip over/run off-road/sink in a lake/etc., you probably won't want to use this method specifically. However, this is a very basic idea, and should get you moving in the right direction. Use this as your base, and figure out what it is you need to accomplish to make the actor spawn somewhere other than it's current location (location of something else), as well as to set it's orientation on spawn (upright, facing the correct direction, etc.).

                      Comment


                        #12
                        Thanks man you're awesome, I'll try this whenever I have time to use my computer and I'll let you know if it works ^^

                        Comment


                          #13
                          Okay it works, but now I want to know how to change it's position to make the vehicle stand up again like you said being able to face the right direction on the track when it spawns.

                          Comment


                            #14
                            One word to point you in the right direction: rotation. (pun completely intended)

                            Comment


                              #15
                              I know you're trying to help me by pointing me in the right direction to figure this out myself, but this is really confusing for me...


                              You could say it's "unreal" :P

                              Comment

                              Working...
                              X