- Home /
How to move Pistol Shutter in VR?
Hi Everyone! I have an issue, can't imagine how to make possible to slide pistol shutter, to reload/load gun in VR(Htc Vive)! I was trying to use colliders, and remember the first interaction point, and relatively to it calculate x movement and implement it to the shutter. So that's the question. Maybe anybody knows how to do it or already did ?
Thank you!
add trigger to the pistol shutter
add trigger to the controller's tip
once
OnTriggerEnter
let's you know the 2 triggers have crossed check if the button is pushed on the controllerwhile the above 2 conditions are BOTH correct do the following: a. move shutter together with the controller (emulate grip) b. if the controller's trigger leaves the trigger on the shutter,
OnTriggerExit
- let shutter go back to rested position (emulate grip release)
EDIT: of course, the pistol is either still or controlled by another controller all the while
What exactly a problem? You want to hold pistol in one hand and pull shutter using another hand?
You can get distance between hand and the shutter and when distance < some threshold, hold button and begin to move shutter to position of the hand (but only on 1 axis, ignore other 2 axis)
Answer by Oyshoboy · May 20, 2017 at 02:11 PM
Everybody thanks for comments and advises, probles solved!
Here is the video demonstration: https://youtu.be/AxFI8FY5KSU
Solved it like this ( function must be called inside OnTriggerStay) :
void CheckHandAndMove(Collider Coll)
{
//check if you using correct hand
if (G17ItemScript.AttachedHand != null && Coll != null)
{
// get steamVR component to detect trigger press
ControllerCheckTrigg = Coll.transform.parent.GetComponentInParent<SteamVR_TrackedController>();
// checking if trigger pressed
if (ControllerCheckTrigg.triggerPressed) {
// Getting hand, which we need to follow
Follow = Coll.transform.parent.parent.gameObject;
// getting relative movement of hand to the shutter
HandRelativeTransform = transform.InverseTransformPoint(Follow.transform.position);
// impmenent movement only for z axis ( using animation blend tree to be inside limits )
G17Animator.SetFloat("Blend", HandRelativeTransform.x * 20);
}
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612122429im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Collision work on pc emulator but not on android device 0 Answers
Excluding Vertices from Cloth Colliders in Unity 5 4 Answers
Softbodies in Unity 3D 1 Answer
Funfair simulation help 0 Answers