- Home /
oculus rift single shot on SecondaryIndexTrigger pull
Greeting Everyone! thanks for stopping by to help me with my issue!
alright so im working on a shooter for the Oculus but when i pull the trigger it fires of all the ammo in my gun very rapidly. since the player is using a revolver this is less than ideal.
i understand that the OVRInput.Get(OVRInput.Axis1D.SecondaryIndexTrigger) returns a 0.0f - 1.0f float.
so what im doing is something like this :
if (isRightHand)
{
indexTriggerState = OVRInput.Get(OVRInput.Axis1D.SecondaryIndexTrigger, Controller);
}
if (indexTriggerState <= 0.1f)
{
shotFiredOnTrigger = false;
}
then later :
if(indexTriggerState >= 0.95f && !lastFrameFired)
if (isRightHand)
{
if (ammoCount >= 1)
{
shootGun();
}
else {
ammoEmpty();
}
lastFrameFired = true;
}
basically it checks for the float value of the trigger. if its almost all the way pulled it tells the game to fire a shot, and sets a bool to say "hey i just fired. don't fire again until the trigger is almost entirely let off.
easy and simple. But te problem is it seems like the float for IndexTriggerState reached .9999 something something on frame then even with the trigger still pulled it drops back down to 0.02 or something really low like that.
im not a great coder but im not awful. this is the first project ive done with oculus and i feel like im beating my head against a wall with this and im sure the answer is right there in front of me i just cant see the trees through the forest.
any help you guys can offer would be greatly appreciated.
Answer by cvid · Mar 17, 2018 at 01:01 PM
Hi, @Saint34x
Instead of OVRInput.Get you can use OVRInput.GetDown with same parameters. These method returns true only once on button down event even if user hold it. In this case there is no need to do any additional checks. For example:
bool bDown = OVRInput.GetDown(OVRInput.SecondaryIndexTrigger, Controller);
if(bDown)
{
Shoot();
}
Hello @cvid thanks for getting back to me. i really appreciate it! so i tried what you said :
bool bDown = OVRInput.GetDown(OVRInput.Button.SecondaryIndexTrigger, Controller);
print(bDown);
this bit makes perfect sense to me and was what i tried to do at first but i wasnt casting the input as its own bool and was trying to check it directly with an if statement. that didnt work. haha
but for some reason this always returns false. is there something else im missing ?
thank you again for your help.
Sorry it was my fault. I've just checked it and correct script will be:
bool bDownLeft = OVRInput.GetDown(OVRInput.Button.PrimaryIndexTrigger, OVRInput.Controller.LTouch); // for left hand
bool bDownRight = OVRInput.GetDown(OVRInput.Button.PrimaryIndexTrigger, OVRInput.Controller.RTouch); // for right hand
As axis it's called Secondary, but for button is called Primary. I really don't know why.
Please note that you need a OVR$$anonymous$$anager instance on scene and in addition you should setup XR settings section in Player Settings with Oculus SD$$anonymous$$. Hope it'll be helpful.
yes!! this works perfectly! thank you so much! you are a life saver.
Your answer
Follow this Question
Related Questions
cannot read button input from oculus go (but able to read rotation) 0 Answers
XR Interaction Toolkit Preview detecting wrong controller 1 Answer
OpenXR Continuous Turn and Movement not working 0 Answers
Gamepad stops working with Oculus Rift attached 0 Answers
How to get VR controls working again after update to 2019.1.0f2? 0 Answers