Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by yakri · Dec 31, 2016 at 10:09 PM · vector3shootingshooteraimingquaternion.lookrotation

Smoothly calculating a vector forward of the mid point between two vectors to allow two handed aiming in VR

Alright so here's a visual of the problem I am having.

I'm trying to allow the player to two handed aim an object by holding their hands/controllers side by side and having the mid point between their hands be the aiming direction for the weapon. While I have sort of succeeded in doing this as if you carefully and slowly position your hands you can do such a two handed aim, this method has resulted in the object wildly swinging around

Ideally I need to lower the sensitivity and lock the aiming range to only 180 degrees forward of the player/controllers so the object can't swing back to face the player.

Unfortunately I've hit the end of my basic knowledge of manipulating vectors and rotations in unity and I've been stumped at this point for ages. Any suggestions on alternative ways to accomplish the same thing or on how to improve my method would be very welcome.

The code I'm using now is as follows.

         private void AimObject()
         {

             Vector3 perp = Vector3.Cross(secondaryGrabbingObject.transform.TransformDirection(Vector3.forward), primaryGrabbingObject.transform.TransformDirection(Vector3.forward));
 
             vSample1 = vSample2;
             vSample2 = perp;
             transform.rotation = Quaternion.LookRotation((vSample1 + vSample2) / 2, secondaryGrabbingObject.transform.TransformDirection(Vector3.forward));
 
         }

This is calculated each fixed update.

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Glurth · Dec 31, 2016 at 11:25 PM 0
Share

"holding their hands/controllers side by side and having the mid point between their hands be the ai$$anonymous$$g direction for the weapon."

But two points are required to specify a DIRECTION. you could have the bullet originate from that point, but you still need another point (or a set of angles) to specify direction.

I guess you could make the direction "Perpendicular" to the line between the hands: but this would be more like a bicycle handle, than a rifle. But then this would ALSO require more information, since straight up, and straight forward could BOTH be perpendicular to the line between the hands, how do you deter$$anonymous$$e which one to use? Or you could make the bullet shoot in a line "Parallel" to the line between the hands, which would be more like a rifle.

secondaryGrabbingObject,primaryGrabbingObject Are these are the "hands"? Should the hand "orientation" count, or just it's position?

What is the location of the "body"? I would suggest something that uses all three of those positions (let me think on that a bit before I suggest any details).

avatar image yakri Glurth · Jan 01, 2017 at 12:55 AM 0
Share

Yes, I am making the points perpendicular to the line between hands, as it is a turret I am trying to make not a rifle. So it's pretty much exactly like bicycle handles, except with up/down directionality needed.

Yes, they are the hands, corresponding to which hand you grab with first.

hand orientation is maybe worth including at least for up/down, but you don't actually want rotating the controllers to affect the aim to make things less messy.

The aim is for the positioning of both controllers to influence the aim.

The head is tracked, but there's no position for the body exactly. Although you could just use the head as the body, or a point somewhat downwards from the head.

avatar image Glurth yakri · Jan 01, 2017 at 02:02 AM 0
Share

Hmm, ok , how does this sound? Since it sounds like the orientation of the hands can get a bit tricky I recommend NOT using them for the ai$$anonymous$$g. Ins$$anonymous$$d add some kind of "pivot" point, in game space, that is a fixed distance in front of the character. $$anonymous$$inda like a machine gun on a tripod's pivot (except the character would actually WEAR the tripod on a harness or something.).

Now, you can use the point between your hands as your first point, and the pivot location as the second point, to give the direction the bullet should travel.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

93 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Shooting A Projectile With an Arc 0 Answers

Aiming and shooting to the same point in third person 1 Answer

Sensing an objects collisions by another object 0 Answers

How do I have my character aim where my mouse cursor is? 2 Answers

Shooting mechanic - can't shoot left and right,2D shooting mechanic - can't shoot lift and right 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges