Software Archive
Read-only legacy content

traslation

agund4
Novice
457 Views

Hi I have a game object (cube).

I am adding translation script to it  from unity tool kit.

It is getting rotated and traslation motion in 3 directions.

But i need it a motion like pendulum(semio circular motion in a plane).

I tried many ways in the script can some body guide.?

0 Kudos
1 Solution
MartyG
Honored Contributor III
457 Views

I think that if you need to limit the directions that your cube can travel in then it is much better to use the Toolkit's TrackingAction script instead of TranslateAction.  With TrackingAction, you can set 'constraints' for the position and rotation axes in the Inspector window to stop the object from moving in the directions that you have ticked in the constraints.  

For example, if you wanted to stop the cube from rotating up and down then you would place a tick in the 'Y' axis box for both its Position and Rotation settings.

I am guessing that you should first place a tick in all three of the TrackingAction's Rotation settings (X, Y and Z) to stop it from being able to rotate at all, and simply use Position movement in the X and Z directions to get your left-right movement with a little in and out.

I went into Unity and succeeded in making what you are trying to do, I think.

STEP ONE

Create your simple cube.

STEP TWO

Place a TrackingAction script inside your cube.

STEP THREE

Click on your cube to show the TrackingAction settings in the Inspector panel and look at the upper half of the TrackingAction settings.  Expand open the 'Hand Tracking' option and select which body point you want to use to move the cube.  You can leave all of the other settings on their defaults and not change them.

1.jpg

STEP FOUR

Go the lower half of the TrackingAction settings and expand open the 'Constraints' option.  Place a tick in all three of the lower 'Rotation' boxes and a tick in the upper Position box of the 'Y' axis.

Leave Position 'X' and 'Z' unticked.  X will allow your cube to move left and right, and Z will allow it to sway in and out.

2.jpg

STEP FIVE

Finally, we are going to define 'Virtual World Box' values.  Thee tell the cube how far it is allowed to travel in either direction (e.g left / right, in / out, up / down) from its start position until it must stop.  

If we want to make the cube like a pendulum then we only want to give it small Virtual World Box values.  The X direction (left-right sway) will have a slightly larger value than the Z direction (in-out) sway.

Give the 'X' box a value of 0.3.  Give the Z box a value of 0.1.  And give the Y box 0.1 also.  

3.jpg

The Y setting will not actually be used by the cube because we locked the Y direction in the constraints.  But if you leave it at 0 then it automatically changes to '1' when the program runs, so I prefer to just set it to 0.1 to prevent that change so I feel that I have control over it.  :)

If you want to change the direction that the cube moves left-right in (e.g north-south instead of west-east), simply swap around the X and Z values so that X = 0.1 and Z = 0.3.

Now you have defined the Virtual World Box values, whenever you click on your cube you will see a red box around it that visually represents the Box values you defined.  This is very useful, as the shape of it shows the directions that your cube will be limited to travelling in.  It cannot move beyond the limits of the red box surrounding it.

4.jpg

STEP SIX

Run your program and use the tracking point that you set (e.g the hand palm) to move the cube around.  You will see that it moves left and right but can also moves in and out a little as it moves left-right.

Best of luck and if you have more questions, please do ask them in the comments!

View solution in original post

0 Kudos
2 Replies
MartyG
Honored Contributor III
458 Views

I think that if you need to limit the directions that your cube can travel in then it is much better to use the Toolkit's TrackingAction script instead of TranslateAction.  With TrackingAction, you can set 'constraints' for the position and rotation axes in the Inspector window to stop the object from moving in the directions that you have ticked in the constraints.  

For example, if you wanted to stop the cube from rotating up and down then you would place a tick in the 'Y' axis box for both its Position and Rotation settings.

I am guessing that you should first place a tick in all three of the TrackingAction's Rotation settings (X, Y and Z) to stop it from being able to rotate at all, and simply use Position movement in the X and Z directions to get your left-right movement with a little in and out.

I went into Unity and succeeded in making what you are trying to do, I think.

STEP ONE

Create your simple cube.

STEP TWO

Place a TrackingAction script inside your cube.

STEP THREE

Click on your cube to show the TrackingAction settings in the Inspector panel and look at the upper half of the TrackingAction settings.  Expand open the 'Hand Tracking' option and select which body point you want to use to move the cube.  You can leave all of the other settings on their defaults and not change them.

1.jpg

STEP FOUR

Go the lower half of the TrackingAction settings and expand open the 'Constraints' option.  Place a tick in all three of the lower 'Rotation' boxes and a tick in the upper Position box of the 'Y' axis.

Leave Position 'X' and 'Z' unticked.  X will allow your cube to move left and right, and Z will allow it to sway in and out.

2.jpg

STEP FIVE

Finally, we are going to define 'Virtual World Box' values.  Thee tell the cube how far it is allowed to travel in either direction (e.g left / right, in / out, up / down) from its start position until it must stop.  

If we want to make the cube like a pendulum then we only want to give it small Virtual World Box values.  The X direction (left-right sway) will have a slightly larger value than the Z direction (in-out) sway.

Give the 'X' box a value of 0.3.  Give the Z box a value of 0.1.  And give the Y box 0.1 also.  

3.jpg

The Y setting will not actually be used by the cube because we locked the Y direction in the constraints.  But if you leave it at 0 then it automatically changes to '1' when the program runs, so I prefer to just set it to 0.1 to prevent that change so I feel that I have control over it.  :)

If you want to change the direction that the cube moves left-right in (e.g north-south instead of west-east), simply swap around the X and Z values so that X = 0.1 and Z = 0.3.

Now you have defined the Virtual World Box values, whenever you click on your cube you will see a red box around it that visually represents the Box values you defined.  This is very useful, as the shape of it shows the directions that your cube will be limited to travelling in.  It cannot move beyond the limits of the red box surrounding it.

4.jpg

STEP SIX

Run your program and use the tracking point that you set (e.g the hand palm) to move the cube around.  You will see that it moves left and right but can also moves in and out a little as it moves left-right.

Best of luck and if you have more questions, please do ask them in the comments!

0 Kudos
agund4
Novice
457 Views

Dear Marty,

Thanks for your detailed explanation.

It helped me a lot

0 Kudos
Reply