Items with no label
3335 Discussions

SR300 player gesture controller

MMoha17
Novice
5,117 Views

Hi,

I have made a Unity game which uses box colliders and triggers actions received from the SR300, to control the player (thanks to MartyG), however, I would like to improve the smoothness of this control, such that I do not want to use box colliders but just simple swipes to the left, right, forward and backwards to move the player. May I know how I can do that?

I have attached my current controller type below.

Thank you

0 Kudos
26 Replies
MartyG
Honored Contributor III
605 Views

If you want the selector to jump to 208, -1, 0 then put in the OnEnable() function this line instead of Vector3.zero:

transform.position = new Vector3(208, -1, 0);

In your SendMessageAction, put the function name as OnEnable

After the selector is moved to 208, -1, 0, the script should run the rest of the script in the order that it is listed. It will run the Awake() function next and set up the newposition variable. Then finally it will run the LateUpdate function and activate the lerp.

OnEnable and Awake will only run once, whilst LateUpdate will keep looping for as long as the script is enabled.

0 Kudos
MMoha17
Novice
605 Views

Hi MartyG,

After doing everything, The only changes are that the Virutal World Box dimensions are changing automatically whenever I press play. This is shown below in Before pressing play and After pressing play below. And I cannot seem to move the canvas box (the white rectangular box) in my inspector. It is greyed out.

Before:

After:

Thank you.

0 Kudos
MartyG
Honored Contributor III
605 Views

I didn't realize that your selector object was attached to a Canvas too as well as your WebCamTexture component. I can understand what you are doing though, as I have a selector object attached to a Canvas in my own Unity project. Moving an object attached to a Canvas is a bit different from moving a non-Canvas object, because the scale is different. For example, you have to move a Canvas object by about '50' to get it to travel the same distance that a non-Canvas object can cover if it only moves by '1'.

Not being able to move a Canvas is a problem I too experienced. you can only move the object that is childed to the Canvas.

My Selector object was not a Canvas. It was a Button object -childed- to the Canvas. How I made it was:

STEP ONE

Highlight the Canvas object in the Hierarchy panel

STEP TWO

Go to the GameObject menu and select UI > Button. This will create a button object that is childed to the Canvas.

STEP THREE

Highlight the new Button object in the Hierarchy panel to see its settings in the Inspector. Remove the 'Button' component.

STEP FOUR

Set the button's Image component to have the texture that you want your Selector to have, by left-clicking on the small circle icon at the end of the 'source Image' option to bring up a sprite selector (the image you are giving the selector object should be a sprite)..

STEP FOUR

Put your SendMessageAction and your selector movement script inside the Button object.

STEP FIVE

Set the transform.position = new Vector3 instruction in your script to move the selector to the Rect Transform coordinates that you want to move it to.

Your selector object should now move to those coordinates on the Canvas when the movement script is activated by SendMessageAction.

0 Kudos
MMoha17
Novice
605 Views

Hi MartyG,

I still face the same problems. The Virtual world box moves down automatically to another coordinate (as shown in the pictures above earlier). If I disable the code:

void OnEnable()

{

transform.position = Vector3.zero;

}

The Virtual box is okay and it does not move. But when I insert the code again, it moves to another coordinate. I have followed all the steps below.

Thank you.

0 Kudos
MartyG
Honored Contributor III
605 Views

In your script's Lerp, you are lerping between 'transform.position' and 'newposition'. But in your Awake function, you made the newposition variable equal to transform.position. So your object is not going to move anywhere, because your script is saying that the position to move to should be the position that you are already at.

If I am reading your intent correctly, I think your lerp should look like this:

transform.position = Vector3.Lerp(positionA, positionB, Time.deltaTime * smooth);

Then it should lerp between the value of positionA (start position) and positionB (where you want the object to move to). Your positionB variable is set as '0, 0, 0', so that is where the object would move to.

0 Kudos
MMoha17
Novice
605 Views
0 Kudos
Reply