Log in or register to post comments

getting a object at touch position

April 28, 2011 - 12:14am #1

Hi

I want an object to pop out at the tap position of my device screen.
Can anyone please help me with it?

getting a object at touch position

January 5, 2018 - 5:12am #14

Hi,

Cube is not showing even after I scale the cube bigger.

getting a object at touch position

January 3, 2018 - 1:59am #13

Hi,

i want a 3d model instantiate  at touch position using vuforia while target image is not showing.

Re: getting a object at touch position

May 9, 2011 - 7:59am #12

I gave you a code snippet for finding the touch point projected to the target plane. Try comparing the current touch position to the last touch position (store it each frame). Then move the object on the plane by that amount.

You can also use the Physics.Raycast method to figure out what object the touch hit.

- Kim

Re: getting a object at touch position

May 9, 2011 - 5:05am #11

thnku Kim..
now i want to move an object along with the finger touch..?? how can i do that...?

Re: getting a object at touch position

May 4, 2011 - 5:29am #10

If you just want the button to show up when tracking is found, and disappear when tracking is lost, do something like this (editing TrackableEventHandler):

private bool mTargetIsVisible = false;

private void OnTrackingFound()
{
    ...
    mTargetIsVisible = true;
}


private void OnTrackingLost()
{
    ...
    mTargetIsVisible = false;
}


void OnGUI()
{
    if (mTargetIsVisible)
    {
        if (GUI.Button(new Rect(10, 10, 150, 100), "click me"))
        {
            print("You clicked the button!");
        }
    }
}

I don't know about getting the name of the button, it isn't a single button object so much as a directive to add a button to the screen each frame (OnGUI is called each frame).

- Kim

Re: getting a object at touch position

May 4, 2011 - 5:19am #9

hey thnx kim..

that button should disappear as soon as image is removed from the camera view. But for that i want the name of the button which is dynamically created. How to get that?
How to disable that button.

Re: getting a object at touch position

May 3, 2011 - 5:31am #8

Try starting with the TrackableEventHandler that comes with the sample applications (Scripts/TrackableEventHandler.cs). You can use the OnTrackingFound method to set a flag indicating the target is visible. Then query this flag in the OnGUI method to render your GUI, something like this:

void OnGUI()
{
    if (mTargetIsVisible)
    {
        if (GUI.Button(new Rect(10, 10, 150, 100), "click me"))
        {
            print("You clicked the button!");
        }
    }
}

- Kim

Re: getting a object at touch position

May 3, 2011 - 12:15am #7

i want a text to come as soon as the camera screen detects the imagetarget and when i click on that particular text then an object should pop out

Re: getting a object at touch position

May 2, 2011 - 6:52am #6

Do you mean a particular text on the target (in 3D space) or on the screen (in 2D space)?

The code I listed above will give you a 3D position on the target. You can check this against a set of "interesting" coordinates (offset from the center of the target) to see how close the tap was, but you'll have to do all that by hand. The SDK doesn't know anything about particular features on the target.

If you're talking about text on the screen, you can create Unity GUI objects that respond to touch. Check out the Unity GUI Scripting Guide: http://unity3d.com/support/documentation/Components/GUI%20Scripting%20Guide.html

- Kim

Re: getting a object at touch position

May 2, 2011 - 12:06am #5

Hey thanx kim.. its working..:)
Now i want an object to pop out only if a particular text is touched then how can i do that..

Re: getting a object at touch position

April 29, 2011 - 5:42am #4

Ah, be sure to mention that in your posts, or post under the Unity section of the forum :)

Unity provides a lot of helpful functions for raycasting into the scene. One approach is to create a Plane object that matches the orientation of your target and raycast against it. Here's a snippet:

void Update ()
{
    // Attach this script to a trackable object
    // Create a plane that matches the target plane
    Plane targetPlane = new Plane(transform.up, transform.position);

    foreach (Touch touch in Input.touches)
    {
        if (touch.phase == TouchPhase.Began)
        {
            Ray ray = Camera.main.ScreenPointToRay(touch.position);

            float dist = 0.0f;
            targetPlane.Raycast(ray, out dist);
            Vector3 planePoint = ray.GetPoint(dist);

            GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
            cube.transform.parent = transform;
            cube.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
            cube.transform.position = planePoint;
        }
    }
}

- Kim

Re: getting a object at touch position

April 28, 2011 - 11:01pm #3

thnku bt i am working with unity3d so can u please provide me with some script for the same.

Re: getting a object at touch position

April 28, 2011 - 5:55am #2

Take a look at the Dominoes sample, it should have all the code you need to get started. When you touch the screen dominoes appear on the target at the touch location.

- Kim

Log in or register to post comments