Announcement

Collapse
No announcement yet.

"Look at object" event in Blueprint

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

    "Look at object" event in Blueprint

    Hi guys,

    I'm currently trying to figure out how to trigger an event (something simple like making a light visible) when the crosshair (i.e center of the screen) is looking at an object.

    Basically like a CursorOver event type thing, but for the crosshair. I assume it will be a bit more complicated than a cursor hover event though haha.

    If anyone could provide some help that would be great.

    An added bonus would be if I could specify a minimum distance away from the object that the player has to be to trigger the event too.



    Quick 'n' Dirty sketch of what I want (obviously simplified a lot):





    I saw this thread but I'm not sure if they were headed in the right direction, and the OP of that thread never actually got a working example from the looks of it.


    Cheers,
    Ben

    #2
    I know this is not the perfect solution, but you could you this one:

    Make a Timer for 100ms or similar. Then do a Single Trace Line and check, if the HitObject is your object. If it is, turn the light on, if not,turn it off
    If you can't really imagine what I mean, I could do a sample BP

    Comment


      #3
      Originally posted by JohnnyCrazy View Post
      I know this is not the perfect solution, but you could you this one:

      Make a Timer for 100ms or similar. Then do a Single Trace Line and check, if the HitObject is your object. If it is, turn the light on, if not,turn it off
      If you can't really imagine what I mean, I could do a sample BP
      A sample BP would be really helpful since I'm having a bit of trouble figuring out the Single Line Trace.

      Comment


        #4
        Here's an example of a setup you could use inside of a place-able Actor Blueprint that has a Point Light as a component:



        Basically, every tick (frame) this blueprint does a line trace from your Player Character's location to a location straight in front of it that is determined by the forward facing vector * the distance you want to trace out (this is where you could set a distance limit so it only activates the light if you are close to it). The trace is then checked to see if you hit the object that's doing the tracing and, if so, turns on the light.

        Hopefully this enough to get you started!

        Comment


          #5
          Originally posted by Steve Allison View Post
          Here's an example of a setup you could use inside of a place-able Actor Blueprint that has a Point Light as a component:

          (redacted)

          Basically, every tick (frame) this blueprint does a line trace from your Player Character's location to a location straight in front of it that is determined by the forward facing vector * the distance you want to trace out (this is where you could set a distance limit so it only activates the light if you are close to it). The trace is then checked to see if you hit the object that's doing the tracing and, if so, turns on the light.

          Hopefully this enough to get you started!
          Thank you very much! I will give it a go when I get home from work.

          Comment


            #6
            It doesn't seem to work...
            A 3D Adventure Game developed using Unreal Engine 4

            Comment


              #7
              Make sure the object that you're checking whether the crosshair is over generates hit events and blocks the visibility channel. Not all objects do this by default.
              DO contact me with questions about Blueprint or other Unreal features! I don't bite! Or charge money! Just press that blue Skype button and fire away.

              Project Culverin - Open Ended First Person Shooter

              Comment


                #8
                I just want to point out that in addition to Steve Allison's solution. If you're character is traversing the world space, the Player Direction and Distance is not enough to calculate the Line Trace. Make sure after the X node to add a Vector + Vector not that connects the X with the Player Location. This will allow you to trace even if the player is moved from their spot.

                Click image for larger version

Name:	Untitled-1.png
Views:	1
Size:	43.1 KB
ID:	1056380

                The only reason why I brought this up is the fact that I found Steve's solution useful but I faced a problem that wasn't present in his example. Hope this helps any lurkers looking for help.
                Current Project: Shadow Over Isolation

                Comment


                  #9
                  Okay so if you are using the First Person Blueprint Template:

                  I created a Simple BP with a Static Mesh of a Lamp & and a Pointlight. My Root element is a capsule component.
                  A Function with a Boolean Parameter inside the Lamp sets the visibility of the Pointlight to the value of the boolean

                  The rest of the VCode is inside the MyCharacter BP fired by the Event Tick


                  1. Create a new Actor* Variable in the MyCharater BP
                  2. you need to correct where the Crosshair is because its not completely renderd to the middle of the screen

                  Click image for larger version

Name:	1.png
Views:	1
Size:	119.8 KB
ID:	1056528
                  The rest is pretty straight forward:
                  Click image for larger version

Name:	2.png
Views:	1
Size:	111.8 KB
ID:	1056529
                  and
                  Click image for larger version

Name:	3.png
Views:	1
Size:	106.7 KB
ID:	1056530

                  as for Part 1 its a simple Line Trace but we need to make the trace come out of our "face" either we get strange results because the trace is not exacly where we are looking at.
                  We need to raise the Z value of our starting Vector to the Z value of our camera component wich is 64 by default.
                  Oh and if you want to lower or raise the range of the trace alter the * 1000 node

                  Part 2 checkts if our trace did hit something if not we check if our Last Lamp Actor var has a value if so we simply turn the light off (we may need to set the light actor to nothing after that... forgot to do that)
                  if we hit something we turn of the light of the last lamp we traced and afterwards we cast the actor we just hit to our Lamp Class and turn the light on if that was successfull

                  this should be everything you need to work with

                  (as you may have noticed english is not my native language... but i hope its still comprehensive

                  Superbad screen capture of my solution:
                  Last edited by ruohki; 09-10-2014, 01:22 PM.
                  Free Inventory System (BP AND C++ Version): Clicky Clicky
                  Player Structure System (Houses!) (BP): Pew Pew Marketplace Version: Yoink!
                  Howto: Create Dragable UMG Windows: Zoom Zoom

                  Comment


                    #10
                    I've got it set up slightly differently. I never use a missed trace to change anything. There is an almost unnoticeable delay after looking away from the item, but I find it scales easier to multiple different items.

                    I have the trace from the first person camera [using location and loc + (x*forward vector) as start and end] send an event to the object through a blueprint interface, which then turns on a lamp with a do-once and then a retriggerable delay that is longer than the trace interval (.2 sec seems to still work, much shorter will cause it to flicker), to turn off the lamp when it no longer gets any additional traces telling it to be on. Once it's turned off, I reset the do-once to turn it on for the next time it's looked at. This way you can choose whether it turns off (almost) immediately or after a little while depending on the delay length. And it shouldn't ever stay turned on because of weird trace hit results or fails not firing as intended.

                    This is the event on the item, after the line trace (per tick) from the player causes it to fire on that item.
                    Click image for larger version

Name:	e8a58d7a9de735e4f0ef3219bd3bf3f8.png
Views:	1
Size:	137.6 KB
ID:	1056555

                    Comment


                      #11
                      Our version is camera relative, and is called on pressing the E key on the keyboard.....

                      Click image for larger version

Name:	CameraRelative.jpg
Views:	1
Size:	394.1 KB
ID:	1065425

                      Comment


                        #12
                        Can you please explain me how did you get switch light input in part 2?

                        Comment

                        Working...
                        X