Tutorial How To Move & Control 3D Object By Touch Dragging Finger By The Screen In Mobile Unity Game
YouTube Viewers YouTube Viewers
29.7K subscribers
80,474 views
0

 Published On Jan 23, 2020

In this video I will show a simple way how to move a 3D object by some surface by dragging your finger by the screen. You will be able to control a game object with touch. Useful Unity touch controls feature is here.

That's a TV set!
Insignia NS-32DF310NA19 32-inch Smart HD TV - Fire TV
https://amzn.to/3lCzxKy

TO BLAST! - My New Fun Relaxing Puzzle Game Available On Google Play Store
https://play.google.com/store/apps/de...

Consider purchasing my ULTIMATE UDEMY COURSE with great discount and get access to all of downloadable resources from all of tutorials once and forever
https://www.udemy.com/how-to-make-gam...

I start from an empty project as usual and set it up step by step. First I need a surface. I create new 3D object which is a plane. It has a boring white color by default so to change that I need to create a new material. I create one, rename it as orange and change its color to orange. After that I just D&D this new material to my plane. Very good. NExt gameobject will be a cube which will be moving. I create a new 3D cube and bring it up a bit. It is white as well so lets change its color. I duplicate orange material by pressing Ctrl + D keys. Rename this new one as Green and change its color to green. D&D this green material to Cube and now it looks much better. Also I add a rigidbody component to this cube so it will lower on my plane and will be moving on it. Ok. To move this cube with my finger I use this script named Move. It’s a pretty simple one. Here it is.

Here I have a couple of variables. Touch variable will hold some useful information about my finger touch such as a number of touches, touch position and so on. And speed Modifier variable will help me not to move my cube too fast. In start method I set this variable to 0.01 so my cube will be moving a hundred times slower than it could. So you can play with this value to get the cube speed you want.

The main magic happens in update method. So if touch count is greater than zero which means that I touch the screen with one finger at least then my touch variable is assigned to the first finger touch which has an index equals to 0. For example if I touch the screen with two fingers at the same time then the second touch has this index equals to 1. And so on. But since I want to manage only one touch in this case so I need to take care only of the first one. Ok. So when I move my finger by the screen then the phase of this touch becomes equal to moved. In this case I change cube position depending on touch delta position which is calculated every frame. So cubes X position is changed depending on fingers x position multiplied by speed modifier, cubes Y position stays the same and cubes Z position is changed depending on fingers Y position multiplied by speed modifier as well.
That’s the script.
D&D this script to the cube.

The last thing to do is to tune my game view a bit since the camera shows not what I want it to show now. So I change main cameras position and rotation this way. Very good.
That’s it. Now I can create an Android apk file and see how it works on my phone.

If you like what I'm doing then you can support me through
www.patreon.com/alexanderzotov
or here
https://www.paypal.me/AZotov
Thank you)

This video is also about:
Tutorial How To Move 3D Object With Touch Dragging Finger By The Screen In Android Unity Game, unity 3d move, touch to move unity 3d, unity move 3d object with touch, unity move 3d character, unity how to make character move 3d, unity 3d move object, how to move player in unity 3d, unity3d movement, unity 3d movement, unity3d move to position,unity3d move to point, unity 3d movement tutorial, unity 3d movement script, unity3d move, unity 3d movement script c#, unity 3d movement rigidbody, unity 3d touch controls, unity 3d3 touch movement, unity 3d touch tutorial, unity 3d touch input, unity 3d drag object with touch, unity drag 3d object, unity3d drag object with finger, unity 3d move object with finger, unity 3d touch move left right, unity 3d touch move left right up down.

show more

Share/Embed