Forum Discussion
jaumet2000
4 years agoHonored Guest
Check if an object is grabbed
Hello guys. I can't find a way to check if an object is grabbed or not, a boolean that is true if it is grabbed and false if it is not. The attached image is the components that the object that I w...
- 4 years ago
There might be an easier solution but when I did this, I also wanted a few other features so I created my own ITransformer and put it in the Grabbable Script. Once you do this, you can just copy-paste the code in the default ITransformer you want. In an ITransformer, there is a method called BeginTransform() that is called when an object is first grabbed and EndTransform() when it is unselected. I'd recommend saving a bool somewhere else that is changed by these methods.
EDIT: If you want to get the gameobject inside the iTransformer script use this (assuming the script is on the gameobject):
_grabbable.Transform.gameObject
JVibes55
3 years agoMember
I solved this in a different way. I needed to know which hand was grabbing the object, not just if it was grabbed. There is a property on the HandGrabInteractable called Interactors that populates with which interactors are grabbing it. So, I added tags to the left and right HandGrabInteractors in my OVRCameraRig and then added this code in a script on the same GameObject as the HandGrabInteractable. If you just need to know if it is grabbed, you probably just to need to know if this is null or not.
public class SomeClass : MonoBehavior {
private HandGrabInteractable _interactable;
void Start()
{
_interactable = gameObject.GetComponent<HandGrabInteractable>();
}
void Update(){
var hand = _interactable.Interactors.FirstOrDefault<HandGrabInteractor>();
if (hand != null)
{
Debug.Log("Connected to hand " + hand.gameObject.tag);
// ... do something interesting with this knowledge
}
}
}
gb1982gb
2 years agoExplorer
This was eassy!
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 2 years ago
- 8 years agoAnonymous