# Instantiating an Object at a rotation equal to Swipe Input

Hey everyone,

Working on a 2D project here and have hit a bump. I’m planning on making it compatible with the iOS platforms, so will have to switch out all the Input.MouseButton functions with Touch functions.

What I’d like to do is make it so that the player can swipe a line on the screen and create a sort of wind stream that will carry off leaves or other game objects that happen to touch or be in that stream. I imagine there may be a few ways to go about making this, but this is the first thing I imagined with my limited experience.

Step 1:

The player swipes the screen. In this case, I’m using a Input.MouseButton two generate two points. Each click converts Input.mousePosition to a Raycast which, when hitting the tr on a trigger box in the background generates a Vector3 hitpoint. Using Debug.DrawLine, I managed to connect the two points with a line - roughly simulating swipe functionality.

Step 2: (where the trouble starts)

I’d like to instantiate another object (probably a cube that has been stretched out into a bar magnet-like shape and “hollowed out”, i.e. no mesh / mesh collider, for convenience sake I’ll call it “clock hand”)here. The caveat is that it needs to align itself to be perpendicular points A / B. I guess you could think of it like a clock with A being the center of the clock and B indicating where the clock hand is pointing. After you get both coordinates, you’d simply place the clock hand to line up with points A/B.

Step 3:

Now that I have my clock hand out (my clock hand) I’d make it so that any object within its area (or entering it’s area) would probably receive Constant Force in the direction that matches where the clock hand is pointing. So if the clock hand is pointing at about 2:00, then objects entering its area will move in the 2:00 direction.

Now I realize I can only ask one question a thread, so I’m going to have to start with step two. I’ve managed to get an object instantiated at that point, but have had less luck getting it to line up along my DrawLine. I’ve tried using transform.rotation = Quaternion.LookRotation(hitPointB - hitPointA, Vector3.XXX) with little luck and I’ve looked into Atan2 but can’t figure out to make it work. Any suggestions? Just to be clear, I’m not asking you to write my code, but if you could point me in the right direction I’d appreciate it. It’d be especially helpful if you could also add how I can use the function Step 2 to come up with the data (Vector3?) that I’d need to apply to the Constant Force component in step 3!

If not, then I’ll muddle through it somehow (hopefully!).

Thanks for your time and sorry for the wall of text!

Have you tried using

``````transform.LookAt(pointB);
``````

?

You’d need to offset the position of the box collider to make sure it starts at one point and ends at the other. As for the rest, you can just use OnTriggerEnter and OnTriggerExit to add and remove constantForce components to rigidbodies as you need.