- Home /

# Instantiating game object

So I have a model which is shown as follows:

As you can see there are two sliders and 2 planes whose scale I have reduced to make them seem like lines. There must be better ways for drawing lines. I want to instantiate an object at the intersection point(red circle). I can move the horizontal and vertical lines (orange) using the sliders and where ever they intersect I want to instantiate a gameobject which can be a small sphere. So how can I approach this problem.

**Answer** by juicyz
·
Jan 19, 2017 at 12:36 AM

You can either find the point of intersection using the planes but likely the best way is to do some math using the slider values to place the red dot. As it seems that the lines will always intersect in some way based on the sliders and constrained position, you should be able to translate the y slider value into a y coordinate and the x slider value into a x coordinate. Place the red circle there :D

When I try to move the slider and use the values the object is moving very far. I tried finding the intersection point using normal vectors of the two planes(transform.up), but when I do a cross product between the vectors it appears to be zero because both of their's normal vector point the same direction can you tell me whether we can use the two normal vectors to find the intersection point?

Not sure if you've already tryed this, but sliders have a min and max value, try seting the minValue = to min cordinate and the max to max, like:

The slider empty is at cordinates (540, 620) thats your min value. Then move the slider to its max and check the cordinate, that will be your max value.

Then set the object position = to each value of the slider: (horizontal.value, verticalSlider.value)

Umm like I said and Search said, dont try to calculate the intersection as that's wasted time and effort. Where you want to place your dot will be at Vector2(horizontal.value, vertical.value). Since it appears by your UI, there will always be an intersection you can just simply get the x and y from the sliders as that is what they represent.

Then you just draw your circle and should also set the parent to the canvas. You are drawing it on the canvas or game? If you need world coordinates then you need to take that Vector2 (Vector2(horizonal, vertical) and convert it to world coordinates using the Camera.ScreenToWorld or something like that.

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.