0
votes

So, here is what i have: SteamVR's hand gameobject 3D sphere.

what i want: The sphere to move to same direction/position as the hand does, but it to move further with a multiplier. E.g. i move the VR controller and the hand moves 1 unit. I want that the sphere moves to the same direction in a same amount of time but e.g. 2 units. how do i do this? i tried simple

sphere.transform.position = ControllerToFollow.position +2f;

but then the sphere is always offset.

2

2 Answers

0
votes

position is a Vector3, which is essentially 3 floats - you can't plus a Vector3 with a float unless you overload the + operator. Otherwise what you can do is the following:

Vector3 followPos = new Vector3(ControllerToFollow.position.x + 2f,
                                ControllerToFollow.position.y + 2f, 
                                ControllerToFollow.position.z + 2f);
sphere.transform.position = followPos;

If you only want it to follow on one axis, then you can do the following:

Vector3 followPos = new Vector3(ControllerToFollow.position.x + 2f, // Follow on x Axis
                                ControllerToFollow.position.y, // Y axis is the same
                                ControllerToFollow.position.z); // X Axis is the same
sphere.transform.position = followPos;

Edit: I think I understand your problem better now. Here's a better version.

if (Vector3.Distance(sphere.transform.position, ControllerToFollow.position) >= 2f)
{
    // Code that makes the sphere follow the controlling
}
0
votes

Just track the movement Delta of the hand and multiply it by a certain multiplier.

At the beginning of the manipulation store

private Vector3 lastControllerPosition;

...

lastControllerPosition = ControllerToFollow.position;

then in every frame compare

var delta = ControllerToFollow.position - lastHandPosition;
// Don't forget to update lastControllerPosition for the next frame
lastControllerPosition = ControllerToFollow.position;

Now in delta you have a movement of the controller since the last frame. So you can assign it to the sphere with a multiplier using Transform.Translate

sphere.transform.Translate(delta * multiplier, Space.World); 

or simply using

sphere.transform.position += delta * multiplier;