- Home /
Navigation using LeapMotion unity
so I need this for one of my projects at internship . i've been stuck here for quiet a while . what the task is is that the leap hands should be able to move realtime in forward and backward direction, something shown at the end of this video . https://www.youtube.com/watch?v=V7XUCIBVEH8 . this works but hands are always in motion i ; is it possible to stop and move hands by use of some gestures ? @Harinezumi @Cresspresso @misher @NEGATIVERAGDOLL
Answer by ElijahShadbolt · May 24, 2018 at 10:49 PM
If you want the hand model to have a fixed rotation on the other axes, then I expect there is no easy solution other than creating your own script like LeapMotion's HandController script.
If you want the red box in the video to stop moving when your hand is level with the horizontal plane, then you should adjust the float values on lines 41 and 43 of the script in the video, until it feels right. Keep in mind that rotation angles can be tricky (it is either -180 to +180 degrees, OR it is 0 to +360 degrees, I don't know which), so you should write it down on paper beforehand to check the ranges are right.
Answer by rtanwar616 · May 25, 2018 at 04:48 AM
i just want the hand to move forward towards the box or backwards away from it . rotation is not important. just two kind of motions. forward backward and stationary if i am not doing anything . any ideas on how to achieve that ?
You could first cache an 'origin' position for where your hand should be considered 'in the middle' between being far forward or backward. Then every frame you could check the distance between the 'origin' and the current position (using Vector3.Distance
), and if it is large enough, you know they are trying to move the box. To check whether it is forward or backward you could use Vector3.Angle
, e.g.
public float $$anonymous$$Distance = 0.2f;
public Vector3 globalOrigin; // set this to where your hand starts.
public Vector3 globalForward = new Vector3(0, 0, 1);
...
void Update() {
// if hand is far enough away from the origin
if (Vector3.Distance(transform.position, globalOrigin) > $$anonymous$$Distance) {
Vector3 fromOrigin = transform.position - globalOrigin;
float angle = Vector3.Angle(globalForward, fromOrigin);
// if hand is extended forwards
if (angle < 45f) {
// move forward
}
// if hand is extended backwards
else if (angle > 135f) {
// move backward
}
}
}
(untested)
ok. and where should I attach this script ?
Or are you wanting the box to copy or follow the forwards/backwards position of the hand?
never$$anonymous$$d the box . let's say there is no box . just the hands. so the the hands move forward or backward or stay stationary . but if and only if there is an object present (for eg. a distant box) hands could move towards it and grab / interact with it .
So I forget the box. There is no box. Only the hand. You want the hand to stay stationary, fixed in place, UNTIL there is something close by that can be held. Then you can move the hand. Is that right?
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Making a bubble level (not a game but work tool) 1 Answer
"fillamount" not appear! 0 Answers
Money System Scripting Problem 0 Answers