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.
"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).
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.
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.
Your answer
Follow this Question
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