Announcement

Collapse
No announcement yet.

Pawn looking at

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

    Pawn looking at

    Hi, is there a method to see if a Player is looking at an actor I've created? I'm making a race game, and I wanna see if the Player is on the wrong way or not.
    Last edited by Scienziatogm; 07-05-2014, 03:40 PM.
    Unreal Engine 4 C++ Programmer

    My projects:
    Ultimate Arena FPS

    Our Discord Server:
    Ultimate Arena FPS Discord

    #2
    Do you use checkpoints? (even if they are hidden and used for laptimes?) If so, just constantly check if the car is approaching the correct checkpoint or not. If they last passed checkpoint 2, and their distance to 2 is increasing while distance to 3 is decreasing, they're going the right way, if the opposite, they are going the wrong way. Combined with some logic to tell them if they've left the track (even if it's just rumbling the car or whatever) will both try to encourage them to stay on the track and point the right way. However if you set it up this way you won't have weird things (based on direction) like if the person is wrecking and spins, or is in a very tight turn, it won't purely be based on what they're facing but in what direction they're moving. You could add a further condition to this not to trigger when off the track, or not to trigger when the car is in reverse, etc.

    Comment


      #3
      Originally posted by Madison View Post
      Do you use checkpoints? (even if they are hidden and used for laptimes?) If so, just constantly check if the car is approaching the correct checkpoint or not. If they last passed checkpoint 2, and their distance to 2 is increasing while distance to 3 is decreasing, they're going the right way, if the opposite, they are going the wrong way. Combined with some logic to tell them if they've left the track (even if it's just rumbling the car or whatever) will both try to encourage them to stay on the track and point the right way. However if you set it up this way you won't have weird things (based on direction) like if the person is wrecking and spins, or is in a very tight turn, it won't purely be based on what they're facing but in what direction they're moving. You could add a further condition to this not to trigger when off the track, or not to trigger when the car is in reverse, etc.
      This is a good idea, but how can I trace the distance from the Pawn to the next checkpoint?
      Unreal Engine 4 C++ Programmer

      My projects:
      Ultimate Arena FPS

      Our Discord Server:
      Ultimate Arena FPS Discord

      Comment


        #4
        Originally posted by Scienziatogm View Post
        This is a good idea, but how can I trace the distance from the Pawn to the next checkpoint?
        This will depend a lot on how your track/checkpoints are implemented, but tracing is covered similarly here https://forums.unrealengine.com/show...t-in-Blueprint (which is a discussion about look at object, which is basically what you're asking in the first place ). I would however work on tracing the spline of the track (assuming that's how you did it, if not adapt as necessary) and in addition using the distance between checkpoints to actually drive the 'wrong way' BP so that it only triggers with motion in the wrong direction instead of just pointing that way (I'm still concerned if you just use a look at object event, if your track isn't an oval like a nascar track, you'll end up frequently triggering the 'wrong way' text when you're on the track going the right direction, you're just simply in a turn that has you pointed 'the wrong way' compared to where the next check point is, when really it's just around some more turns.

        Comment


          #5
          Originally posted by Madison View Post
          This will depend a lot on how your track/checkpoints are implemented, but tracing is covered similarly here https://forums.unrealengine.com/show...t-in-Blueprint (which is a discussion about look at object, which is basically what you're asking in the first place ). I would however work on tracing the spline of the track (assuming that's how you did it, if not adapt as necessary) and in addition using the distance between checkpoints to actually drive the 'wrong way' BP so that it only triggers with motion in the wrong direction instead of just pointing that way (I'm still concerned if you just use a look at object event, if your track isn't an oval like a nascar track, you'll end up frequently triggering the 'wrong way' text when you're on the track going the right direction, you're just simply in a turn that has you pointed 'the wrong way' compared to where the next check point is, when really it's just around some more turns.
          I did this, but it doesn't work:

          Unreal Engine 4 C++ Programmer

          My projects:
          Ultimate Arena FPS

          Our Discord Server:
          Ultimate Arena FPS Discord

          Comment


            #6
            So how is it not working?

            Step through each part and confirm you are getting the results you expected, if you are - then explain why it's not working, if you are not - what parts specifically are not working? Can you test with just that part and see if you can find the issue?

            If you know how you want your BP flow to work, step through each part of your idea and confirm it works as you go, putting together an entire idea and then trying to figure out why it doesn't work is rarely easy to do.

            Comment


              #7
              Originally posted by Madison View Post
              So how is it not working?

              Step through each part and confirm you are getting the results you expected, if you are - then explain why it's not working, if you are not - what parts specifically are not working? Can you test with just that part and see if you can find the issue?

              If you know how you want your BP flow to work, step through each part of your idea and confirm it works as you go, putting together an entire idea and then trying to figure out why it doesn't work is rarely easy to do.
              When I press W, I see this:


              This is the Actor I've placed:


              Why it never says "Wrong way!!" if I go on the wrong way?
              Unreal Engine 4 C++ Programmer

              My projects:
              Ultimate Arena FPS

              Our Discord Server:
              Ultimate Arena FPS Discord

              Comment


                #8
                This is a very simple but non-ideal and time-consuming solution.

                Create new Blueprint named BP_WayPoint. The blueprint will have a variable of type Int wchis is public (with name Index). Within the compoent setup, add a spahre or box collsion component and Block to false, but make sure Generate Overlap is enabled. Inside you Charcter blueprint add a varible of type Int (named ActiveIndex).

                During level design, you will place instances of BP_WayPoint along your rece-track and edit the Index variable from 0,1,2.... ie The waypoint at start of the track will have index 0, the next one will have 1 and so on. This is the time-consuming part.

                In the Character blueprints BeginPlay event, you will set ActiveIndex to 0.

                In the BP_WayPoint blueprint's event graph, add event for BeginOverlap. In this event, you check if the value Index variable of the overlapped WayPoint is greater than ActiveIndex. If it is, then you are going in the proper direction. Otherwsie you are going the wrong way. In either case, you will update the ActiveIndex with the Index of the overlapped WayPoint

                You will need addiotnal logic to make sure the message is not shown when you are reversing (sicne the index will decrement in this case).

                The accuracy of this method depnds on how well you place the WayPoint objects. In a strignt road, you only need one at the start and end. But at turns, you might need more WayPoints.

                Actually you could reduce the level designers work (of setting indices) by making the WayPoint obejects hold a refrence to each other (like a linked list). But once you get this simple emthod working, you will be able to figure taht out yourselves.

                Advantages:
                Very simple logic.
                No tracing so better performance.
                You can make ti work in tight curves.. by poerply placing the WayPoints.

                Disadvantages:
                Time consuming. In bigger tracks, setting all the indices is very tiring.
                Will not work if the track has branches.
                I expected challenges - but I never thought they'd be so bad, so long, and so frequent.

                Comment


                  #9
                  Hi. I am the 3D artist on this project. Our track will definately include braches/shortcuts therefore the suggestion kindly provided by mindfane probably won't solve the issue in this specific case.
                  CEO - AceGamer Network
                  Our multiplayer FPS game: http://store.steampowered.com/app/436260/

                  Comment


                    #10
                    Originally posted by Zeb89 View Post
                    Hi. I am the 3D artist on this project. Our track will definately include braches/shortcuts therefore the suggestion kindly provided by mindfane probably won't solve the issue in this specific case.
                    I have been experimenting with several techniques and the following one might work for you.

                    What you need.

                    1. A blueprint BP_WayPoint extended from Actor with the following setup.
                    * Components
                    Click image for larger version

Name:	wp_component.jpg
Views:	1
Size:	166.2 KB
ID:	1052405
                    * A public float variable named 'Radius'

                    * Construction script
                    Click image for larger version

Name:	wp_construction.jpg
Views:	1
Size:	43.1 KB
ID:	1052406

                    Event attached to 'Begin Overlap'
                    Click image for larger version

Name:	wp_begin_overlap.jpg
Views:	1
Size:	110.5 KB
ID:	1052407

                    2. A blueprint extended from Pawn/Character with the following setup.
                    * A variable named 'Active Waypoint' of type Object'BP_WayPoint_C'
                    * A boolean variable named 'bWrongWay' with default value set to 'false'
                    Click image for larger version

Name:	character_variables.jpg
Views:	1
Size:	65.4 KB
ID:	1052408

                    * A function named 'Set Active Waypoint'
                    Click image for larger version

Name:	charcter_set_function.jpg
Views:	1
Size:	113.1 KB
ID:	1052409

                    * Event attached to 'Tick'
                    Click image for larger version

Name:	character_tick.jpg
Views:	1
Size:	106.1 KB
ID:	1052410

                    3. A blueprint extended from HUD with following event graph to display Wrong Way text.
                    Click image for larger version

Name:	hud.jpg
Views:	1
Size:	95.4 KB
ID:	1052411

                    How does it work:

                    The BP_Waypoint blueprint must be placed along the track to indicate waypoints. The rotation of this Actor indicates the desired rotation of the car at that point (the arrow component will help with this). You dont have to be very precise. You need to place these actors wherever there is change in direction in the track. You can place them in branches as well. Edit the property of 'Radius' to set the correct radius for the collision sphere.

                    The Pawn has a reference to one instance of BP_Waypoint actor. This is set when Pawn overlaps with a Waypoint. We use the function SetActiveWaypoint function to do this.

                    At each tick, we find the difference between the rotation of the pawn and rotation of ActiveWaypoint. If the difference of Yaw is above a threshold (160 degrees in this example), we set bWrongWay to TRUE, otherwise FALSE.

                    In the HUD, we simply check the value of bWrongWay and display the warning.

                    This is a very basic setup. You must take velocity, reversing etc into consideration. This implementation only looks for the rotation of the Pawn. You can for instance set WrongWay only after Pawn has moved in the wrong direction for a minimum of X distance or Y seconds.. Do this in tick and set bWrongWay accordingly. You can add additional code inside SetActiveWaypoint to optimize things and also to make more complex stuff.

                    This method works with branches as well. However just try to avoid overlaping waypoints.
                    Last edited by mindfane; 07-06-2014, 12:14 PM.
                    I expected challenges - but I never thought they'd be so bad, so long, and so frequent.

                    Comment


                      #11
                      Originally posted by mindfane View Post
                      I have been experimenting with several techniques and the following one might work for you.

                      What you need.

                      1. A blueprint BP_WayPoint extended from Actor with the following setup.
                      * Components
                      [ATTACH=CONFIG]6351[/ATTACH]
                      * A public float variable named 'Radius'

                      * Construction script
                      [ATTACH=CONFIG]6352[/ATTACH]

                      Event attached to 'Begin Overlap'
                      [ATTACH=CONFIG]6353[/ATTACH]

                      2. A blueprint extended from Pawn/Character with the following setup.
                      * A variable named 'Active Waypoint' of type Object'BP_WayPoint_C'
                      * A boolean variable named 'bWrongWay' with default value set to 'false'
                      [ATTACH=CONFIG]6354[/ATTACH]

                      * A function named 'Set Active Waypoint'
                      [ATTACH=CONFIG]6355[/ATTACH]

                      * Event attached to 'Tick'
                      [ATTACH=CONFIG]6356[/ATTACH]

                      3. A blueprint extended from HUD with following event graph to display Wrong Way text.
                      [ATTACH=CONFIG]6357[/ATTACH]

                      How does it work:

                      The BP_Waypoint blueprint must be placed along the track to indicate waypoints. The rotation of this Actor indicates the desired rotation of the car at that point (the arrow component will help with this). You dont have to be very precise. You need to place these actors wherever there is change in direction in the track. You can place them in branches as well. Edit the property of 'Radius' to set the correct radius for the collision sphere.

                      The Pawn has a reference to one instance of BP_Waypoint actor. This is set when Pawn overlaps with a Waypoint. We use the function SetActiveWaypoint function to do this.

                      At each tick, we find the difference between the rotation of the pawn and rotation of ActiveWaypoint. If the difference of Yaw is above a threshold (160 degrees in this example), we set bWrongWay to TRUE, otherwise FALSE.

                      In the HUD, we simply check the value of bWrongWay and display the warning.

                      This is a very basic setup. You must take velocity, reversing etc into consideration. This implementation only looks for the rotation of the Pawn. You can for instance set WrongWay only after Pawn has moved in the wrong direction for a minimum of X distance or Y seconds.. Do this in tick and set bWrongWay accordingly. You can add additional code inside SetActiveWaypoint to optimize things and also to make more complex stuff.

                      This method works with branches as well. However just try to avoid overlaping waypoints.
                      It doesn't work.

                      The pawn BluePrint:


                      The BP_Waypoint (I named it Checkpoint):


                      The HUD:


                      The Set Active Waypoint function:


                      The BP_Waypoint Components:
                      Unreal Engine 4 C++ Programmer

                      My projects:
                      Ultimate Arena FPS

                      Our Discord Server:
                      Ultimate Arena FPS Discord

                      Comment


                        #12
                        Solved. I used the trigonometric math. Thanks to iveytron.

                        https://answers.unrealengine.com/que...ooking-at.html
                        Unreal Engine 4 C++ Programmer

                        My projects:
                        Ultimate Arena FPS

                        Our Discord Server:
                        Ultimate Arena FPS Discord

                        Comment


                          #13
                          Originally posted by Scienziatogm View Post
                          Solved. I used the trigonometric math. Thanks to iveytron.

                          https://answers.unrealengine.com/que...ooking-at.html
                          Glad you got it figured out!!

                          However could you help me out if you don't mind? Does this method work correctly when there are hair-pins in the track (ie 180 dgree turns). Does it show Wrong Way when you make the turn? I am very much interested in this topic. So I'm looking for different techniques.

                          It doesn't work.
                          Could you tell me what did not work exactly? You didn't see any 'Wrong Way' messages on the top-left corner?

                          Anyway check these:
                          The Blueprint extended from Pawn must be the Player charcter (in you case this would mean you need to extend from Vehicle).
                          Make sure the HUD blueprint is the one beign used in GameMode
                          Check collsion settings and see if Begin Overlap is fired correctly.
                          I expected challenges - but I never thought they'd be so bad, so long, and so frequent.

                          Comment


                            #14
                            Originally posted by mindfane View Post
                            Glad you got it figured out!!

                            However could you help me out if you don't mind? Does this method work correctly when there are hair-pins in the track (ie 180 dgree turns). Does it show Wrong Way when you make the turn? I am very much interested in this topic. So I'm looking for different techniques.



                            Could you tell me what did not work exactly? You didn't see any 'Wrong Way' messages on the top-left corner?

                            Anyway check these:
                            The Blueprint extended from Pawn must be the Player charcter (in you case this would mean you need to extend from Vehicle).
                            Make sure the HUD blueprint is the one beign used in GameMode
                            Check collsion settings and see if Begin Overlap is fired correctly.
                            You can set the Wrong Way with a simple check.
                            For example I set a Branch and I put a condition (the result of ACOSd < 45).

                            About your Blueprint, it doesn't say anything.
                            Unreal Engine 4 C++ Programmer

                            My projects:
                            Ultimate Arena FPS

                            Our Discord Server:
                            Ultimate Arena FPS Discord

                            Comment

                            Working...
                            X