Announcement

Collapse
No announcement yet.

How to open a door only if the player has a specific number of points?

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

    How to open a door only if the player has a specific number of points?

    To start off, sorry for using UE 4.9, but unfortunately have to as my college only has that version.

    Okay, so I am making a game where you shoot at targets, and those targets will give you 10 points for each, I want to have it so that the player cannot open the door to the next room unless their score reads, for example, 40. I am new to Unreal and I have no idea how I would do this!

    Any help would be greatly appreciated! Thank you in advance!

    (If you could maybe post screenshots or a step-by-step bulletpoint list on what I need to do, that would probably help me a lot!)

    #2
    The proper way to ask this type of question is to show the work you have already done. It sounds like this is some sort of homework assignment.

    Comment


      #3
      All you need to do is cast from the door to the player character and get the score variable, compare it to the min score needed, and if its greater then open the door.
      Stylized Low Poly Environment
      Stylized Low Poly Pine Forest
      Stylized Low Poly Buildings
      First Person Horror Template

      Comment


        #4
        I made some small project that has door, and some scores. Sadly Its in 4.11 because i do not have any older unreal builds.
        Here is link: https://www.dropbox.com/s/4b1bjyx0dotkv5b/Door.rar?dl=0

        It also has example of dispatchers and interfaces, and some very basic HUD that displays points collected.
        Also pickups that tell player they were collected etc.
        Last edited by Nawrot; 05-25-2016, 09:06 PM.

        Comment


          #5
          Couldn't he use a Blueprint Interface and make it modular? So he can save himself sometime.

          Comment


            #6
            i have a tip for you search on youtube for how to make a door that opens if you have 40 points in unreal engine 4

            Comment


              #7
              Maybe a little read up on variables can point you in the right direction. Using a variable to store the score and trigger the door opening animation is one way you can do it.

              Comment


                #8
                what Zyleq said is good advice. Create a variable of float or int and name it score, make it public, and increment it as necessary. Then have a branch who's condition is that your score is 40, or whatever you want it to be, and then have that branch open the door if the condition is true. There are also many other ways to accomplish this.

                Comment


                  #9
                  This would be the most helpful comment so far, declare variables, create loops/nested loops and set the conditions

                  Comment


                    #10
                    this is just an idea that might help, im also new to unreal engine, you need to set up a system that increments each time the target is hit, each score surface should have an individual id, but the same math will be basically the same, each time the person hits the area it must update the hud saying +10 or something like that, the score area (where the total score is shown) should increase aswell, have the score amount set to a specific id. make an if statement that only runs if the door is activated, and set it to check if the score id equals to the target amount, if it does it opens, if not, it should tell the player that they are useless and need to go back and shoot some more. im not really good at explaining in txt format, and i have a weird sense of humor.

                    Comment


                      #11
                      There's several way to approach this. One method is to setup variables within your PlayerCharacter script (or wherever most of your variables are stored). Set a trigger instance for the door, a variable (integer) that calculates your current score, and perhaps a NoHolDor variable (integer) that has the 40 point value needed to trigger the door opening sequence. Using the HUD file you likely created for the game, the text box that holds the current score can be setup with a binding that translates the data that represents your score to a text format that you can later use for validating your conditions. In Blueprints, you can take the trigger event (while referencing your player of course) and create a branch to handle the actions (true/false) while declaring a condition (e.g. integer >= integer node) with the current score tapped into the upper input pin of the node and the NoHolDor variable in the bottom input pin of the same node.

                      One book I highly recommend is the Blueprints Visual Scripting for Unreal Engine by Brenden Sewell. It covers this in great detail and explains what you are practicing and why it's important. Having spent most of my time in UDK while attending school for Game Design you can imagine how ****** I was when UE4 came out less than a year after I graduated. Now that I've had the chance to burn through lessons and realize UE4's true potential I love it now more than ever.

                      Comment


                        #12
                        Create Game Instance to Store Score Variable and Provide a Place to Access It, things in Game Instances are persistent and remain throughout the game.
                        Click image for larger version

Name:	Create Game Instance.jpg
Views:	1
Size:	207.2 KB
ID:	1112162

                        In your game Level Script/Blueprint add a variable reference to the Game Instance you created so you can easily access variables and functions in it.
                        Click image for larger version

Name:	AddGameInstanceReferenceVariable.jpg
Views:	1
Size:	288.4 KB
ID:	1112163

                        In your Game Instance add a Score variable of type Integer and create Add Score Function.
                        Click image for larger version

Name:	CreateScoreVariableAndAddScoreFunction.jpg
Views:	1
Size:	320.0 KB
ID:	1112164

                        Create a Reset Score Function.
                        Click image for larger version

Name:	AddResetScoreFunction.jpg
Views:	1
Size:	67.0 KB
ID:	1112166

                        Create a Check Score Function.
                        Click image for larger version

Name:	AddCheckScoreFunction.jpg
Views:	1
Size:	317.0 KB
ID:	1112167

                        Create a Get Current Score Function.
                        Click image for larger version

Name:	AddGetCurrentScoreFunction.jpg
Views:	1
Size:	311.7 KB
ID:	1112168

                        Here are the Function Blueprints.

                        Add Score Function:
                        Click image for larger version

Name:	AddScoreFunction.jpg
Views:	1
Size:	231.7 KB
ID:	1112165

                        Reset Score Function:
                        Click image for larger version

Name:	ResetScoreFunction.jpg
Views:	1
Size:	198.7 KB
ID:	1112169

                        Check Score Function:
                        Click image for larger version

Name:	CheckScoreFunction.jpg
Views:	1
Size:	225.3 KB
ID:	1112170

                        Get Current Score Function:
                        Click image for larger version

Name:	GetCurrentScoreFunction.jpg
Views:	1
Size:	215.6 KB
ID:	1112171

                        Create a Door Blueprint:
                        Click image for larger version

Name:	CreateDoorBluePrint.jpg
Views:	1
Size:	247.0 KB
ID:	1112172

                        Create Door Animation, such as with a Matinee Actor or Timeline:
                        Click image for larger version

Name:	CreateDoorAnimation.jpg
Views:	1
Size:	348.5 KB
ID:	1112173

                        Add a Matinee Actor variable to the Door Blueprint and create an event to play the animation when called, in the Details tab select your Open Door Matinee Actor containing your open door animation so it is linked with the Matinee Actor variable in the Door Blueprint so the Door Blueprint has access to the Matinee Actor in the level and the playback works.
                        Click image for larger version

Name:	DoorBlueprint.jpg
Views:	1
Size:	238.6 KB
ID:	1112174

                        Now select the Door in the level and create a reference to it in the Level Script so the Level Script can access it and call the events, functions, or variables on it, then setup input to a test keyboard key like the T key, and compile and save everything after setting the Score Limit and Score Amount to add for each time the Add Score and Check Score functions are called.
                        Click image for larger version

Name:	LevelBlueprintScript.jpg
Views:	1
Size:	371.1 KB
ID:	1112175

                        Press Play and then press T key 4 times, you will see the score increment as it is printed to the screen, and once the T key has been pressed 4 times it will playback the open door animation once the score gets to 40. The score will automatically reset back to 0 and you can repeat the process.

                        The result is this Score 10, 20, and 30 on T Key 3 presses:
                        Click image for larger version

Name:	Score 30.jpg
Views:	1
Size:	231.8 KB
ID:	1112178

                        And on the 4th T key press for Score 40 it plays the door animation, which how I set my animation moves the door to the right a bit.:
                        Click image for larger version

Name:	Score 40.jpg
Views:	1
Size:	227.7 KB
ID:	1112179

                        The Unreal Engine Content Examples, the example Game Content and Templates, and online on YouTube are a good place to learn more, a lot of tutorials and examples are also on the official Unreal Engine YouTube channel, website, and in documentation online and the wiki.

                        If I had to give any good advice for a beginner, it would be try and keep things simple as much as possible and not overcomplicate, because we often get stuck and have tendency to focus so much on the details that the simple functionality for simple gameplay that is more complete could be done much faster with sticking to simple functionality, and it's about what makes a game fun and enjoyable in the long run.
                        Last edited by KnightTechDev; 07-17-2016, 08:27 AM. Reason: Added final note.
                        KT Dev Blog:
                        https://sites.google.com/site/knight...evelopers-blog

                        Comment


                          #13
                          I feel like there is a much easier way to do this. I mean, you could simply Cast to the player like stated before, but in the door hold a variable called something like "Required Score" make it either a float (if you have a decimal value) or an integer (if its just a simple number like 10, 15 or 20) and then in the player blueprint, when the player tries to open the door run a quick check to see if the players current score (variable inside the player blueprint) is equal to or greater than the doors required variable, if so then open door. Really basic, really easy. You don't need to make game instances or access 50 different blueprints to run a simple comparison between a current value and a required value. (I said put the required score in the door blueprint, because if you have a different door that requires a different score, then you can make that required score different than the first door, but the check against the door could be the same) If you need, I can literally setup a quick example in under 20 minutes for you.

                          Comment


                            #14
                            Originally posted by SymCreations995 View Post
                            I feel like there is a much easier way to do this. I mean, you could simply Cast to the player like stated before, but in the door hold a variable called something like "Required Score" make it either a float (if you have a decimal value) or an integer (if its just a simple number like 10, 15 or 20) and then in the player blueprint, when the player tries to open the door run a quick check to see if the players current score (variable inside the player blueprint) is equal to or greater than the doors required variable, if so then open door. Really basic, really easy. You don't need to make game instances or access 50 different blueprints to run a simple comparison between a current value and a required value. (I said put the required score in the door blueprint, because if you have a different door that requires a different score, then you can make that required score different than the first door, but the check against the door could be the same) If you need, I can literally setup a quick example in under 20 minutes for you.
                            While it may seem like a little of an overkill, adding a game instance is the proper way to do it.

                            Though the door design above is rather poor I my opinion. Definitely should a score variable be added, as SymCreations995 suggested. Additionally, the door should have a OnAttemptOpen event which is called every time the player tries opening it; this event will then check whether all prerequisites for opening the door are met: the prerequisite may just be score for now but in case the requirements change in a future version, it is easy to just change the event's implementation right in the door. If you have the player check it, like above, this may lead to the player class becoming very complex and difficult to maintain. Also, having the player perform the check violates the single responsibility principle as it should only be handling player input (and therefore notifying the weapon to fire).

                            Ideally, you also add a target actor, or an actor component which marks its owning actor as target. Either way, the target should be notified when a projectile hits it and increase the score. In the approach of creating a target actor class, simply listen for an OnActorBeginOverlap or OnActorHit event, depending on who projectiles are set up to collide. In the approach of creating an actor component, you need to bind a callback function in C++ to the OnActorBeginOverlap or OnActorHit delegate object, again depending on how collisions are set up; it might be able to bind the parent actor's overlap and hit events in a component in blueprints, too, though I am not sure how and hope somebody else will be able to answer that. By creating this target actor you take away the score updating responsibility from the player class. This way the player class will only have one responsibility: handling user input (which notifies a weapon to fire among other actions like walking, jumping, etc.). You could simply use the first person shooter template adding the door, and target classes.

                            By the way, you can find the single responsibility principle, which I used to justify my design, and four other very important ones right here.
                            Last edited by Dominik Peacock; 09-14-2016, 06:45 PM.

                            Comment


                              #15
                              What college are you going to?

                              Comment

                              Working...
                              X