VR - How to grab object and move it only in Z axis

I am using the VR template, and I am trying to create an object that I can grab and then move up and down a wall in the z axis only. I started with the template grab-able object and replaced the static mesh with my object, but I cannot figure out how to adjust the blueprint. Currently, the blueprint uses an attach node, which attaches my object to the VR hands and inherits its’ location, rotation, etc. This would be great if I could somehow constrain it to only follow the hands z position, but I can’t figure it out. I tried constraints in the physics area of the static mesh component, but those settings seem to be overridden by the blueprint scripts. Any thoughts on how to adjust the attached blueprint to make this work?

Depending on what you want to do, you could forgo the attachment altogether and just set its location directly while the button or trigger is held. So something like this pseudocode:

if (ViveController.Trigger.isheld)
{
    Object.SetActorLocation(Object.GetActorLocation().x, Object.GetActorLocation().y, ViveController.GetActorLocation().z)
}

This way its x and y never change, just the z, being the same as the controller’s z.

Thanks Jared,
In theory I think that is the logic I am trying to achieve, but I should be more specific and say I have no idea how to do it in blueprints. I am more familiar with javascript in Unity, and this blueprint thing is still really hard to navigate for me.

I tried doing something like what you said, but I am pretty lost in blueprints so I could be completely on the wrong track. What I came up with looks like this:

When I grab the object it disappears so I assume my transform stuff is wrong and it is jumping somewhere else in space.

Pretty close, actually. I’d just use the set actor location nodes instead of the whole transform since it would then be doing less stuff each frame and setting the whole transform affects the rotation and scale as well. With your current setup all you have to do is get actor location for self then break vector and plug x and y values from that into the make vector you already have.

Right now you’re setting the object’s x and y values to be 0, so it’s kind of snapping to the world origin, not counting the z. You gotta put in its current values so they won’t change.

And also one more thing, this will only work for one frame - what you’re going to want to do is have this location setting happen on Tick instead of EventPickup. Tick > Sequence > Gate > SetActorLocation. Then on the gate, set “open” to be triggered by the input event for motion controller trigger pressed, the “closed” triggered by motion controller trigger released.

Thanks for the detailed explanation. I made the adjustments you mentioned and it is working. A lot of this stuff I didn’t even realize were in here, so this was very helpful.

Please put your BP screen

@azollinger - do you have a screenshot of your blueprint of how you made this work. I’m trying to do this but only for the x and y axis not z?

Since I tackled the same issue here my bp of the cube object which only gets moved in z axis. One important thing to change is in the BP_motioncontroller > ReleaseActor. There the check if an object is attached or not needs to be bypassed. Otherwise the dropped event is not getting sent.

Here the changed BP_motioncontroller network:

Also, I was not really able to get the motion conroller reference through a new variable. I was only able to use the Pickup event “Attach To” to get it. Any idea why that is?