Announcement

Collapse
No announcement yet.

Character Rotate to Cursor Location

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

    Character Rotate to Cursor Location

    Evening all. I've spent some time trying to get this working, to no avail.


    I simply want the character to rotate towards the cursor location on screen. In a top down perspective.

    I have it working like this.
    Click image for larger version

Name:	vpQpGHZ.png
Views:	1
Size:	197.1 KB
ID:	1195948
    But this isn't ideal as it is tracing for objects under the cursor, as opposed to using the actual screen location of the cursor.

    As you can see in this video, with my mouse held still, the character snaps to different rotations when i move under an object and back out again.
    https://youtu.be/yZGxb6Ylpec

    So. I'm trying to do something like this...
    Click image for larger version

Name:	OKjABUX.png
Views:	1
Size:	135.7 KB
ID:	1195949
    In theory this would work a lot better. But I just can't seen to get it working in any usable way.

    I tried printing the return values of the nodes like this
    Click image for larger version

Name:	T6nAxol.png
Views:	1
Size:	295.6 KB
ID:	1195950
    But the values from the hit result under cursor and the Get Mouse Position are completely different.


    Any one have any ideas how to go about getting this working correctly?

    Thanks in advance! Much appreciated!

    #2
    There's many ways to do it.

    1. Go to your Project Setting --> Engine --> Collision and add a new Object Channel
    2. When you Get Hit Result Under Cursor by Object, drag a pin from the Object Types, make an array and set the above-mentioned Object Channel there
    3. Ensure that your floor mesh is using collision Custom Preset and Collision Type is set the Object Channel you created

    Click image for larger version

Name:	object channel.png
Views:	1
Size:	36.9 KB
ID:	1115950

    Another way to do it is to project a plane and trace for intersections (Plane Origin is your floor):

    Click image for larger version

Name:	project.png
Views:	1
Size:	135.5 KB
ID:	1115954

    Comment


      #3
      Thanks for the response.

      Unfortunately, neither of those are really ideal.
      The first one, Every single object used as floor would need to be tagged. What about when the cursor is over a wall, or an object? The player will just face 0,0,0.

      And the second one isn't ideal as the game will be 3D. You will be able to move up and down all the time.


      The only way to make it work is to have the player face the position of the cursor on screen. As opposed to any objects in the scene. That just doesn't make sense to me. It just doesn't work either.


      I need to get the mouse location in screen space and get some kind of usable information from that to rotate the character.


      Cheers!

      Comment


        #4
        ConvertMouseLocationToWorldSpace does exactly that. Mouse position in 3d space. In this case, Line Trace should do the trick:

        Click image for larger version

Name:	Untitled.png
Views:	1
Size:	137.8 KB
ID:	1115988

        Comment


          #5
          Cheers for the response Everynone. Unfortunately that setup has the same issue as in the video above.

          See here https://youtu.be/WEyuUPkAhRo


          Thanks again!

          Comment


            #6
            Could you not break the World Location and World Direction from ConvertMouseLocationToWorldSpace, split the Start & End on the LineTraceByChannel, then only drag in the X & Y values?

            Comment


              #7
              I did exactly that.
              http://i.imgur.com/T7MlNBW.png

              It still jerks the character around when your cursor moves over any objects.

              As you can see here.
              https://youtu.be/XvATeH-n2zs

              Thanks again all!
              Last edited by Thorax; 09-29-2016, 09:13 PM.

              Comment


                #8
                If you really want a quick and dirty solution, use the line intersection method. Instead of using floor's position as the Plane Origin, use your character's position instead. Anyway, whether the player goes up and down does not matter, get the coords that you need.

                To be honest, you will be limiting yourself if you take the easy way here. I still suggest you use the object channels. It's a tad more work but you will be able to obtain more information about your world this way, especially at a later stage. And no, you do not need to 'tag' everything - not by hand at least. If your levels are going to me made out of modular pieces, you can have a class with the desired settings and instantiate, in the editor or during run-time, swapping meshes and materials as needed.
                Last edited by Everynone; 09-30-2016, 04:23 AM.

                Comment


                  #9
                  I think your suggestion of using the character position or floor position might be a good solution.

                  I'm not trying to take the easy way or the dirty way. I'm just looking for a solution that works well.

                  I can see what you mean about the object channels. Seems like more work than is needed. Not sure what more information I would need about the world.

                  Comment


                    #10
                    Originally posted by Everynone View Post
                    If you really want a quick and dirty solution, use the line intersection method. Instead of using floor's position as the Plane Origin, use your character's position instead. Anyway, whether the player goes up and down does not matter, get the coords that you need.

                    To be honest, you will be limiting yourself if you take the easy way here. I still suggest you use the object channels. It's a tad more work but you will be able to obtain more information about your world this way, especially at a later stage. And no, you do not need to 'tag' everything - not by hand at least. If your levels are going to me made out of modular pieces, you can have a class with the desired settings and instantiate, in the editor or during run-time, swapping meshes and materials as needed.
                    Still trying to get this working better.

                    I don't suppose you could go into more detail. I think I understand what you are suggesting. But I'm not sure how to go about setting it up.

                    Based on your previous advice. This is what I have set up so far.
                    http://imgur.com/nWOm5NK
                    It sort of works. The camera doesn't jolt if the cursor moves over an object. But the character doesn't seem to face where the cursor is located.

                    Scratch that. I was being dim. I used the character location as the input for the "Find Look at Rotation" "Start". And it seems to be working brilliantly.

                    Thanks again.
                    Last edited by Thorax; 10-16-2016, 03:06 PM.

                    Comment


                      #11
                      Glad to hear that!

                      Comment


                        #12
                        Originally posted by Everynone View Post
                        Glad to hear that!
                        Thanks for the pointers. I really appreciate it. Sorry for being a dumbass! haha

                        Thanks again! Very much appreciated.

                        Comment


                          #13
                          Old thread, but just wanted to share it helped me but I can suggest a further improvement.

                          When creating the upright plane, set the plane's origin to the location of your weapon. This way the line projected to the mouse position will be from the barrel of the gun and shots will go perfectly where the cursor is.

                          If you use the character's location the shots will always go above your cursor.

                          Comment

                          Working...
                          X