Announcement

Collapse
No announcement yet.

How do I make something move towards the play when not in view, and stop moving when visible

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

    How do I make something move towards the play when not in view, and stop moving when visible

    Hello. I am working on a little project, and I have been working on something, but no luck. I am trying to make an AI that will move when not visible, but will stop when you look at it.

    Any help is appreciated!

    #2
    This is one way I can think of doing it. Do this inside your AI's class, and replace Cube for your AI player.

    So get the distance between the player and the AI by subtracting their locations in world space, then normalize this to get a value between 0-1. Next find the Dot Product of this normalized vector and the Player's Forward Vector. If the return value is >= 0.0 then they are facing away from the AI, if it's <= 0.0 they are facing towards the player.

    Edit: From the branch you can then do AI Move To, to move to the Player.

    Click image for larger version

Name:	Untitled.png
Views:	1
Size:	135.9 KB
ID:	1131864
    Last edited by Jamie95; 07-31-2017, 07:22 PM.

    Comment


      #3
      How do I get the blue nodes xD

      Comment


        #4
        I just did this in the Level Blueprint quickly, inside your AI character you could create a variable and change the type to be your player character. Then in the AI's Begin Play, set that variable to "Get Player Character". Then you can use that variable in place of the "FirstPersonCharacter2" nodes in my image. The node that's called Cube, replace that for the "Self" node.

        If you're still unsure, let me know and I'll try and remake it using an AI and Player class.

        Comment


          #5
          Got everything, however the AI still wont move, not sure how to make it do so.

          Here's What I tried: https://blueprintue.com/blueprint/v2d-3_-l/

          Doesn't seem to move.
          Last edited by Dr. Zoidberg; 07-31-2017, 10:04 PM.

          Comment


            #6
            Make sure the AI is inside a Nav Mesh.

            Comment


              #7
              Originally posted by Jamie95 View Post
              Make sure the AI is inside a Nav Mesh.
              Unless I need more than a NavMesh Bounds Volume or whatever I do

              Comment


                #8
                Hello, i haven't use it since a long time but maybe trouble comes from that in your ai move to, the pawn input would be self and target actor input player character not the opposite as actually.

                Comment


                  #9
                  https://blueprintue.com/blueprint/ckp42cvg/ Here's what I have now

                  Still doesnt work, and I get these errors:
                  Error Blueprint Runtime Error: Accessed None trying to read property CallFunc_GetAIController_ReturnValue from function: 'ExecuteUbergraph_SCP-173' from node: Teleport in graph: EventGraph in object: SCP-173 with description: Accessed None trying to read property CallFunc_GetAIController_ReturnValue
                  Error Blueprint Runtime Error: Accessed None trying to read property CallFunc_GetAIController_ReturnValue from function: 'ExecuteUbergraph_Testmap' from node: Teleport in graph: EventGraph in object: Testmap with description: Accessed None trying to read property CallFunc_GetAIController_ReturnValue
                  Last edited by Dr. Zoidberg; 08-01-2017, 07:40 PM.

                  Comment


                    #10
                    Try this as a test inside your AI's class: https://blueprintue.com/blueprint/6qjqmd_q/

                    I'm only using a static mesh to test this, not a skeletal mesh or proper AI. You'd need to use Behavior Trees and Blackboard with BehaviorTree Task Nodes to properly use AI if you're not already.

                    Try this series. Looks like it goes quite in-depth in creating basic AI using just Blueprint: https://www.youtube.com/watch?v=VAAHKNoIg0w
                    Tesla Dev also explains it kinda well: https://www.youtube.com/watch?v=h0Kb42oCoYg
                    Last edited by Jamie95; 08-01-2017, 10:31 PM.

                    Comment


                      #11
                      Works pretty much the only way I need it to, however could I make it so it wont go inside the player, and so it will move when you can't see it through objects, finally how about force it to go around objects?
                      Last edited by Dr. Zoidberg; 08-02-2017, 04:21 AM.

                      Comment


                        #12
                        You'll need to set up Behavior Trees with tasks properly to do stuff like that properly, if you didn't already, you should really check out Tesla Dev's video, https://www.youtube.com/watch?v=h0Kb42oCoYg he explains how to move the AI around a nav mesh which will force the AI to go around objects.

                        If you want to make it so the AI will also move when the player is obstructed by an object there are many ways you can do this. The easiest is to use the Pawn Sensing Component, I know it has an OnSeePawn event so you could use that to say stop moving the AI when this event is triggered. Alternatively you could have a sphere collision of however big you want the AI to be able to "see". OnComponentBeginOverlap cast to the player and do LineTraceByChannel with the start location being the AI's world location and the End being the Player's world location. On the Hit Actor, cast to the player, if the cast is successful that means there is nothing blocking the view between the AI and Player.

                        Pawn Sensing Component: https://www.youtube.com/watch?v=59INcP9Vsmo

                        Comment


                          #13
                          https://blueprintue.com/blueprint/o56-290i/

                          Done everything I need except where it will move through an object, and it will move when your vision is obstructed. I connected the return value to the condition on the branch, and still no luck. Not sure if I missed anything or what the case is.
                          Last edited by Dr. Zoidberg; 08-02-2017, 02:12 PM.

                          Comment


                            #14
                            Yeah with the SetActorLocation it will move through objects, I only did SetActorLocation as a test to make sure it moves etc., you will need to use the AI MoveTo node inside a behavior tree task class which will use Unreal's A* pathfinding algorithm on the nav mesh to navigate around objects.

                            Comment


                              #15
                              UE crashes when I use AIMoveTo

                              Comment

                              Working...
                              X