Jump to content

Grab object using script


Recommended Posts

I am investigating to see if Vive Input Utility can replace NewtonVR for proper collision detection in my application. It looks like the Sticky Grabbable component works in a similar way and my tennis racket does not go right through the ball, so that's promising.

But It only works when pressing a button. There is a large range of possible buttons to select from, but in my application I am using a script to attach the racket to the correct controller (depending on the player's dominant hand) or tracker if that is used. I don't want to bother the player with the action of picking up the racket in every drill they do.

How can I achieve this?

And another question (but maybe I should make a separate thread out of it): Is it possible to make the Following Duration shorter than 0.02 (seconds, I guess)? I see a remark in the code that it depends on the Update rate, so if I would set fixedDeltaTime to let's say 0.001 (1 ms), can I then get a following duration of 0.001 as well? ( I know I need to add both the [SteamVR] and [ViveInputUtility] prefabs in the scene and in both uncheck the 'Lock physics update rate to render frequency' option to avoid falling back to 90 fps at runtime)


Link to comment
Share on other sites

@chengnay Here's what I did as a test:

I started with the ColliderEvent example scene and imported my racket and ball. I found out that the behaviour I need is the one that is on the StickyBockableRigidbody, so I copied the Sticky Grabbable script component from that object to my tennis racket. Now when I move either the left controller or the right controller over the tennis racket and press the trigger the racket is attached to the controller. And it's sticky, so I can release the trigger.

What I would like to happen is that I have my own script, RacketControlSelector which does something like this (pseudo-code);

switch (player.dominantHand)
    case Right:
    case Left:

void GrabRacketWithController (controllerToUse)
    // Call the functionality in StickyGrabbable that is executed when the user presses the trigger Is this OnGrabRigidBody()?
    // You could see it as a virtual trigger press by controllerToUse

The remark about the Following Duration is in RigidPose.SetRigidBodyVelocity(), which is called from GrabbableBase.OnGrabRigidBody()

Link to comment
Share on other sites

Hi jboss,

Since the Duration question is more about frame rate, yes I think it should be in a separate thread if you don't mind.

So am I to understand that you don't want the stickiness to occur on grab (with button press) but on collision? So is the dominant hand assumed to be the one grabbing or is it specified elsewhere first? I also I didn't understand why stickygrabbable would be different than grabbable regarding having racket going through the ball - that's more about collider's material options and RigidBody collision options.

Link to comment
Share on other sites

Thanks @Dario

What I want is that the grab occurs at the start of the scene. Some background: I have a tennis application that is used for training (not a game) and the athlete can choose from a number of drills. It starts with a selection scene where the athlete can select if they are right- or lefthanded and if they use the controller in their hand or the tracker on the racket. And then they select the drill they want to do. Typically during a practice session they will do several drills. Each drill is a separate Unity scene, so at the start of each scene the racket should be attached automatically to the correct controller or to the tracker and at the correct position and rotation.

You're right, the stickyness itself is not related to the collision detection. But if I use the Transform option the collision is not detected. And I do need the stickyness to avoid that the racket is released right at the next frame after attaching, because the trigger is no longer pressed. This is what happened when I tried the SteamVR interaction system earlier this year (https://steamcommunity.com/app/250820/discussions/7/3148519094654061096/).

I created a new topic for the Following Duration question: 


Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...