Announcement

Collapse
No announcement yet.

Calculating angle of hit from an "weapon" in VR

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

    Calculating angle of hit from an "weapon" in VR

    Okay. So i've been racking my brain with this for a while but cannot seem to fathom how to do it with blueprints.

    Basically in my project i have a situation where an target is supposed to be stunned. This mean that the stun weapon needs to be closed enough to the target and not have a big angle (something like 10 is okay, 45 isn't)
    My problem is that i cannot wrap my head around how to do it. It must be something stupidly obvious but still. I know the formula for the calculation but cannot transfer it to the blueprints.

    Any pointers or help would be greatly appreciated! And anyway have a great day.

    #2
    Eyo,

    Could you maybe elaborate a bit as I have some issues understanding what you mean by "the stun weapon needs to be closed enough to the target" is it the Enemy targets weapon or the player's weapon that hit the target? In what context is this happening.

    When I have a hard time understanding the problem I start with Paint, and if it still is hard I go for my programmer ducks/cardboard dogs.

    Comment


      #3
      dot product is cosinus of angle. If it does not matter if angle is positive or negative then dot product between impact vector and normal vector to hit surface is all you need.
      If you want also left\right information you need to make another dot product with right vector of impact and normal (to get if direction is positive or negative). But that is used for player controllers mostly.

      this little critter is what you need:
      https://docs.unrealengine.com/en-US/...uct/index.html

      Ps. make sure you NORMALIZE both vectors that you put into dot.

      Comment


        #4
        You might find this article on Dot product interesting for your application: https://www.gamedev.net/articles/pro...n-games-r2968/

        Comment


          #5
          Try something like this

          Click image for larger version

Name:	Untitled1.jpg
Views:	86
Size:	59.2 KB
ID:	1734031

          Camera - is camera forward vector.

          Comment


            #6
            Originally posted by Celldelning View Post
            Eyo,

            Could you maybe elaborate a bit as I have some issues understanding what you mean by "the stun weapon needs to be closed enough to the target" is it the Enemy targets weapon or the player's weapon that hit the target? In what context is this happening.

            When I have a hard time understanding the problem I start with Paint, and if it still is hard I go for my programmer ducks/cardboard dogs.
            Ahh sorry about that. To try and clarify is that there are animals you need to stun with a weapon (this is educational so mimicks what you would do in real life) and in real life you need to get the stun gun pressed against the animals head straight and without an angle on or you risk hurting the animal instead of blacking it out. (i hope the the picture at least somewhat helps to explain it.)

            I need to calculate the angle of hit to see if it was done properly. Sorry for being so unclear with this ^^'
            Attached Files

            Comment


              #7
              Originally posted by Nawrot View Post
              dot product is cosinus of angle. If it does not matter if angle is positive or negative then dot product between impact vector and normal vector to hit surface is all you need.
              If you want also left\right information you need to make another dot product with right vector of impact and normal (to get if direction is positive or negative). But that is used for player controllers mostly.

              this little critter is what you need:
              https://docs.unrealengine.com/en-US/...uct/index.html

              Ps. make sure you NORMALIZE both vectors that you put into dot.
              That is somewhere along what i've been thinking i'd say, just have had a hard time putting it into code. Needed as much validation to my thinking as actual help. Will have a look at that, thank you!

              Comment


                #8
                Originally posted by FunAndFriendly View Post
                You might find this article on Dot product interesting for your application: https://www.gamedev.net/articles/pro...n-games-r2968/
                Will most certainly give it a good read, thank you for your help!

                Comment


                  #9
                  Originally posted by Mr. Wood View Post
                  Try something like this

                  Click image for larger version

Name:	Untitled1.jpg
Views:	86
Size:	59.2 KB
ID:	1734031

                  Camera - is camera forward vector.
                  Will give it a shot and see what i can make of it. Thank you for your assistance!

                  Comment


                    #10
                    Oh,
                    Yeah, it sounds like something a dot product could help you out with, just make sure that you calculate from the right location.

                    Depending on the design and setup of the StunGun and if you always need to press it towards the animal's head you might be better off with colliders on each side, where all of them need to "collide" for it to succeed.

                    Good Luck!

                    Comment

                    Working...
                    X