Pinch to Zoom and Panning on Mobile in Unity

  Рет қаралды 74,978

Waldo

Waldo

Күн бұрын

Пікірлер: 198
@fluorescente
@fluorescente 2 жыл бұрын
oh I wasted time in other tutorials and this one is the simplest and only working one! thanks!
@jorgecano6927
@jorgecano6927 4 жыл бұрын
Thanks for the nice tutorial! Already subscribed. In case anyone has trouble with the zoom acting weird when you don't release the fingers at the same time, I think I found a solution (based on the solution proposed by 현빈 in the comments below): Add a private bool variable name at the start, like multiTouch = false; In the if (Input.GetMouseButtonDown(0)) set multiTouch = false; In the if (Input.touchCount == 2) set multiTouch = true; In the else if (Input.GetMouseButton(0)) add this condition "&& multiTouch == false". Hopefully that'll help somebody. Thanks again man
@Sinhalaparanikatha
@Sinhalaparanikatha 4 жыл бұрын
that's what I was looking for. thanks, bud. i worked perfectly
@williambae5753
@williambae5753 2 жыл бұрын
thank you so much!
@sistemasintegrales3658
@sistemasintegrales3658 6 жыл бұрын
I don't know if I didn't hear if (if not sorry) but should state that camera must be set in Orthographic Projection.
@kurtiskucera6712
@kurtiskucera6712 6 жыл бұрын
You just saved me from pulling out my hair!! Thank you so much.
@magicquest5221
@magicquest5221 5 жыл бұрын
i wonder why it doesn't work with perspective
@rogertorres6088
@rogertorres6088 5 жыл бұрын
@@magicquest5221 it's the . Use instead. In addition, you will have to grab the "cameraStart" at the same time you grab "touchStart" and then, instead of you will have to do something like . The 20f is because there's something I'm missing regarding these space conversions, but you sure can figure if you wanna invest the time
@aadityakiran_s
@aadityakiran_s 4 жыл бұрын
Also the Canvas has to be set to World Space
@yuvgro
@yuvgro 6 жыл бұрын
Was looking all over for a good touch gesture tutorial, Thanks man, keep up with the good quality. Subscribed!.
@spartanh1438
@spartanh1438 3 жыл бұрын
best video on this topic ive found so far
@erkambilalbal7170
@erkambilalbal7170 3 жыл бұрын
THANK YOU A LOT! THIS ONE HELPED ME IN MY PERSONA PROJECT(IB) A LOT. THANK THANKS A LOT. YOU ARE A PERFECT PERSON.
@N1ghtR1der666
@N1ghtR1der666 3 жыл бұрын
You sir are a gentleman and a scholar, I have been trying to work this out for a while and there are not many tutorials on this exact functionality
@festival_91
@festival_91 4 жыл бұрын
Great video to get things started!! watching this video after more than two years.
@lordheman
@lordheman 4 жыл бұрын
Thanks man! I've been tinkering with this all day, and your code just works flawless!
@numerikachamba5976
@numerikachamba5976 2 жыл бұрын
That's awesome big man, keep the fire burning🔥🔥🔥🔥🔥
@thuvienanime5441
@thuvienanime5441 3 жыл бұрын
start I zoom Camera with touchCount =2 , then I lift 1 hand. At this time the camera is not standing, it is moved by one hand I still touch. how can i fix it? thank you !
@kapkoder4009
@kapkoder4009 4 жыл бұрын
Dude your TUTORIALS are LITERALLY amazing! Great quality and content! Thanks for the lecture...
@santiagoaguirre6928
@santiagoaguirre6928 4 жыл бұрын
how can you restrict the panning for the camera?
@fluorescente
@fluorescente 2 жыл бұрын
I'm trying to find a script to fill the screen with objects, like the one you mention at the beginning, any ideas?
@Dacommenta
@Dacommenta 2 жыл бұрын
at 6:40 your voice temporarily went from Nerd to Jock 🤣😂 thanks for the video!
@hegworks
@hegworks 4 жыл бұрын
Wooooooow Really appreciate this It is very clear and straightforward. THANKS!
@cubedev4838
@cubedev4838 4 жыл бұрын
You should make tutorial series bro!! Clear explaination
@nbgamesllc
@nbgamesllc 2 жыл бұрын
I realize this is an old video but how would I update this to work with a canvas background instead of just a sprite?
@emman6602
@emman6602 2 жыл бұрын
Great Tutorial! :D May I ask if how will I setup a boundaries for the cameras?
@INeatFreak
@INeatFreak 5 жыл бұрын
What an awesome tutorial!! it's much better then Brackeys RTS Camera video.
@chakravarthye
@chakravarthye 5 жыл бұрын
Awesome tut Waldo. Beautifully explained :)
@zekrollahnaserie545
@zekrollahnaserie545 6 жыл бұрын
Can you show me how to do this in 3d?
@Kidopya
@Kidopya 3 жыл бұрын
Hello, how can i restrict camera movement and set limits to it? To make camera stay in reasonable positions... with pinch zoom
@fodk7021
@fodk7021 3 жыл бұрын
Use Mathf.Clamp(Camera.main.transform.position.x, MinX, MaxX); You can do this with other coordinates.
@samuelrussell5259
@samuelrussell5259 3 жыл бұрын
Still working in March 2021. Great tutorial!
@blameyourm8519
@blameyourm8519 4 жыл бұрын
Can you please explain how does direction variable work?! I don't understand!
@thanhtrucngo4623
@thanhtrucngo4623 4 жыл бұрын
thank you waldo, very cool and insightful tutorial! i'm glad i found you ;)
@rimia1650
@rimia1650 3 жыл бұрын
hi, many thanks for your tutorial. I used your code, everything is fine but Rotate var doesn't work. can you explain Rotate Boolean variable work?
@XtremClanchannel
@XtremClanchannel 5 жыл бұрын
As soon as I put two fingers on the screen, the camera jumps constantly from max to min zoom value and back. Im doing it with a perspective camera but i already testet it with orthographic too. Same problem. Can anyone help?
@samivtg
@samivtg 4 жыл бұрын
XtremClanchannel same problem :(
@nirportal7208
@nirportal7208 4 жыл бұрын
yes, same here
@I-find-John-Titor
@I-find-John-Titor 3 жыл бұрын
Thanks you! Have a nice day!
@-jkr0570
@-jkr0570 5 жыл бұрын
Dude! This tutorial is a high quality vid. More please!
@ridnur8982
@ridnur8982 4 жыл бұрын
Can it work for AR in Unity? I want to create a zoom in/out touch gesture to it.
@radneypalacios1380
@radneypalacios1380 6 жыл бұрын
Can it be possible to set the position of the camera to an object in the start of the scene? and not just on the center of the plane?
@AsToldByWaldo
@AsToldByWaldo 6 жыл бұрын
Radney Palacios yes. In your start function just set the cameras transform.position equal to the objects transform.position.
@radneypalacios1380
@radneypalacios1380 6 жыл бұрын
@@AsToldByWaldo thanks bro, it helped me a lot. Is there any way where I can set the starting zoom of the camera to the target object? and I got this problem because the camera does not center to the target object.
@AsToldByWaldo
@AsToldByWaldo 6 жыл бұрын
Radney Palacios check out this video I made on my other channel. It’ll help you calculate the perfect zoom. kzbin.info/www/bejne/aam7naGJmtl7hq8
@radneypalacios1380
@radneypalacios1380 6 жыл бұрын
@@AsToldByWaldo Thanks a lot bro.
@SellusionStar
@SellusionStar 5 жыл бұрын
Appreciate this quality content. Very well done! :)
@simonk5361
@simonk5361 6 жыл бұрын
Hallo @As Told by Waldo i tried many things but it still do not work in my scene. The Canvas is on World Space and the EventCamera is the Main Camera. Inside the Canvas i hava a image that i can see if i pan or zoom. But nothing happens. What shuold i do?
@AsToldByWaldo
@AsToldByWaldo 6 жыл бұрын
PhönixOnTV check out this video: kzbin.info/www/bejne/apCrhp93e9Grrbc
@simonk5361
@simonk5361 6 жыл бұрын
Thanks love your Tutorials
@anonymoussloth6687
@anonymoussloth6687 4 жыл бұрын
Also, will this work if i used this script in 3d but kept camera in ortho? with a random rotation also?
@zexzill
@zexzill 5 жыл бұрын
Great video ! Nice and clear explanation :) thanks, big respect from indonesia.
@hazemtv630
@hazemtv630 2 жыл бұрын
didnt work for me it said Object reference not set to an instance of an object and it and this are repeated maybe 60 times help
@Croccolucho
@Croccolucho 4 жыл бұрын
how can i do this but with 2 fingers on the screen?
@prathamesh_dalvi
@prathamesh_dalvi 6 жыл бұрын
Can u tell how to write code to distribute the icon ..As u wrote
@AsToldByWaldo
@AsToldByWaldo 6 жыл бұрын
Create a parent object to hold all the icons and attach a script with this code to it. public float maxPerCol; public float padding; // Use this for initialization void Start () { float row = 0; float col = 0; foreach (Transform child in transform){ Vector2 childPos = child.transform.position; childPos.x = row * padding; childPos.y = col * padding; child.transform.position = childPos; if(col >= maxPerCol){ row += 1; col = 0; }else{ col += 1; } } }
@prathamesh_dalvi
@prathamesh_dalvi 6 жыл бұрын
@@AsToldByWaldo Thanks very very much...
@vigneshsree3115
@vigneshsree3115 5 жыл бұрын
how to perform animation by pinch to zoom in unity for ex a car having tyre, alloy, break etc.when i zoom it will get animated by coming out of the tyre when i zoom out it will get move to the previous position
@tutorialslibrary5422
@tutorialslibrary5422 5 жыл бұрын
Sir How Can we restrict pan movement like we Only want panning On image One check is when we zoom in then panning enable as well and other I want to restrict pan movement so camera don't go away from image
@Ibrahimhaxhiu
@Ibrahimhaxhiu 4 жыл бұрын
How to put borders so the camera can't go any further
@jeremybayot8889
@jeremybayot8889 6 жыл бұрын
Hi. Is it possible to put a limit according to the size of the scene? Great tutorial by the way! This worked very well on my Android application.
@AsToldByWaldo
@AsToldByWaldo 6 жыл бұрын
Yeah you could setup boundaries on your object and limit movement based on that. This other video I made might help you in the right direction. kzbin.info/www/bejne/l5rPk6awpdmSd6s
@jeremybayot8889
@jeremybayot8889 6 жыл бұрын
Thanks!
@williamwoods8977
@williamwoods8977 4 жыл бұрын
Can you do a tutorial on mobile touch or does this work with that too. thanks.
@arthurshulman
@arthurshulman 4 жыл бұрын
We found Waldo, and gosh darn good one.
@mesutyavuzx
@mesutyavuzx 5 жыл бұрын
not working... i did drop to maincamera but not working
@emiljonsson3600
@emiljonsson3600 6 жыл бұрын
I just copy-pasted the script but when i run it in game mode it says: NullReferenceException: Object reference not set to an instance of an object PanZoom.zoom (System.Single increment) (at Assets/Scripts/PanZoom.cs:43) PanZoom.Update () (at Assets/Scripts/PanZoom.cs:38) new to this so i don't have a clue what im doing wrong
@abhijitroy3180
@abhijitroy3180 5 жыл бұрын
*Great tutorial!* Please help! How to make panning only in zoom in mode. And stop the panning in full screen mode.
@prathamesh_dalvi
@prathamesh_dalvi 6 жыл бұрын
Do u imported 380 icon one by one(By Dragging)..Or U have Any method to do it ?
@符贝磊
@符贝磊 5 жыл бұрын
Hello dude, I want to know how to limit the camera view just in the icon area...
@unexpert
@unexpert 6 жыл бұрын
How do I increase the rate of zoom? I have a very large image. Thank you
@AsToldByWaldo
@AsToldByWaldo 6 жыл бұрын
You can multiply the increment in your zoom function by a multiplier: void zoom(float increment){ float multiplier = 1.25f; Camera.main.orthographicSize = Mathf.Clamp(Camera.main.orthographicSize - increment * multiplier, zoomOutMin, zoomOutMax); } Keep increasing the value of multiplier until it zooms at the speed you like.
@unexpert
@unexpert 6 жыл бұрын
@@AsToldByWaldo Thank you! Works great~
@laloutayao03
@laloutayao03 5 жыл бұрын
How about if i want to pan only on Y-axis? Like up and down only? For selecting floors...
@edgunther8136
@edgunther8136 5 жыл бұрын
Instead of setting the camera transform equal to direction, set the camera position.y to direction.y You May have to make a new vector 3
@techd
@techd 5 жыл бұрын
@@edgunther8136 Can anyone expand on how to lock it to only one axis.
@bensamasoni8243
@bensamasoni8243 4 жыл бұрын
​@@techd I did this by using this tutorial kzbin.info/www/bejne/apCrhp93e9Grrbc and changing my camera to be perspective instead of orthographic. After that there's only a couple changes you need to make. The code should look like this: using System.Collections; using System.Collections.Generic; using UnityEngine; public class SwipeDetector : MonoBehaviour { private Vector3 touchStart; public Camera cam; public float groundZ = 0; //public float minHeightX, maxHeightX, minHeightY, maxHeightY; // Update is called once per frame void LateUpdate () { if (Input.GetMouseButtonDown(0)){ touchStart = GetWorldPosition(groundZ); } if (Input.GetMouseButton(0)){ Vector3 direction = touchStart - GetWorldPosition(groundZ); direction.x = 0; direction.z = 0; cam.transform.position += direction; } } private Vector3 GetWorldPosition(float z){ Ray mousePos = cam.ScreenPointToRay(Input.mousePosition); Plane ground = new Plane(Vector3.forward, new Vector3(0,0,z)); float distance; ground.Raycast(mousePos, out distance); return mousePos.GetPoint(distance); } }
@darryldoe4991
@darryldoe4991 5 жыл бұрын
Good tutorial! It works for me when Im using a sprite as my background. But it doesnt work if I use my canvass using the ui scale mode - scale with screen size where my ui elements are
@jericobaladhay1988
@jericobaladhay1988 3 жыл бұрын
How do you solve if I am using Scale Mode - Scale with Screen Size?
@danilob5304
@danilob5304 6 жыл бұрын
How do you clamp this?
@ivavoy2800
@ivavoy2800 6 жыл бұрын
Thanks man. I have a problem though... The zoom in/out is super slow for me. How can add speed to that function?
@AsToldByWaldo
@AsToldByWaldo 6 жыл бұрын
iva voy just multiply the increment (replace SPEEDVALUE below with a float value): void zoom(float increment){ Camera.main.orthographicSize = Mathf.Clamp(Camera.main.orthographicSize - (increment * SPEEDVALUE), zoomOutMin, zoomOutMax); }
@ivavoy2800
@ivavoy2800 6 жыл бұрын
It didn't work. I put exaclty that and my testing values were 10 - 100 - 1000 with no response....?
@AsToldByWaldo
@AsToldByWaldo 6 жыл бұрын
iva voy don’t put exactly that. Replace SPEEDVALUE with a float number. Like 1.5f
@ivavoy2800
@ivavoy2800 6 жыл бұрын
I was missing the "f". Thought float values were simple numbers inside a float variable. Thanks man it works great!!
@AsToldByWaldo
@AsToldByWaldo 6 жыл бұрын
iva voy Glad I could help.
@renskloosterman4045
@renskloosterman4045 5 жыл бұрын
Hey Waldo, great tutorial! But i've ran into a problem. When you try it on mobile, and you start zooming but don't release your fingers at the exact same time, the program will think you started panning and the camera will jump. Do you by any chance have a solution for this?
@걐-n7n
@걐-n7n 5 жыл бұрын
hello i'm korean novice Developer. i think for that problem and i solve that. That's Add int touchC2 = 0; if(Input.touchCount >= 2) {isMulti touch = 1; } if (isMultitouch == 1 && (Input.touchCount == 1|| Input.touchCount == 0)) { direction = Vector2.zero; touchStart = Camera.main.ScreenToWorldPoint(Input.mousePosition); isMultitouch = 0; } else if (Input.GetMouseButton(0) && isMultitouch == 0)
@MsMaddeW
@MsMaddeW 4 жыл бұрын
@@걐-n7n I have the same problem, where in the script do you add "int touchC2 = 0;" ? Thanks!
@anonymoussloth6687
@anonymoussloth6687 4 жыл бұрын
How to pan using touch? u covered zooming but how to pan?
@paulpachikara6597
@paulpachikara6597 5 жыл бұрын
Hey for some reason, everything in this tutorial did work for me. Like non of the panning nor zooming functions worked at all. Does anyone know why?
@nikunjsethi9351
@nikunjsethi9351 4 жыл бұрын
Change the camera view from Perspective to Orthographic
@маркшкриба
@маркшкриба 6 жыл бұрын
help please!) I am trying to add your script to the main camera but it not allows me to do it and shows me this message:Can't add script behaviour VisualContainerAsset. The script needs to derive from MonoBehaviour!
@AsToldByWaldo
@AsToldByWaldo 6 жыл бұрын
Make sure you copy and paste the entire script. You need to have monobehaviour at the top: using System.Collections; using System.Collections.Generic; using UnityEngine; public class PanZoom : MonoBehaviour { copy and paste it here: www.astoldbywaldo.com/tutorials/2018/07/12/44/pan--zoom.html
@AffanKhan-lv3ok
@AffanKhan-lv3ok 4 жыл бұрын
Sorry a little late, but if anyone else has this problem, make sure that the name of the actual script matches the name of the public class: For example, "public class ***PanZoom*** : MonoBehaviour" Change that bit to the name of the script
@ghazihumamfauzan3310
@ghazihumamfauzan3310 5 жыл бұрын
the script error.. a note appears "the script needs to derive from monobehaviour", what happened?
@_inpeymus3603
@_inpeymus3603 6 жыл бұрын
doesn't have the limit for maximum viewable displayed image in the scene
@saumyasaurav159
@saumyasaurav159 6 жыл бұрын
Can you do a Tutorial Video on *How to Make Character Inventory System & Unlockable character, like the one in Color Switch*
@AsToldByWaldo
@AsToldByWaldo 6 жыл бұрын
I'll see what I can do :)
@gamerplanet5252
@gamerplanet5252 5 жыл бұрын
great explanation. Thanks Waldo
@comboyx1977
@comboyx1977 5 жыл бұрын
Loved how to the point you explained. I will take back my like if it doesn't work when I get back home :) thanks
@MaverixGamesStudio
@MaverixGamesStudio 5 жыл бұрын
ty man, save my life!
@biseshshakya4006
@biseshshakya4006 6 жыл бұрын
NullReferenceException: Object reference not set to an instance of an object CameraController.Update () (at Assets/Scripts/CameraController.cs:56) I get this error
@AsToldByWaldo
@AsToldByWaldo 6 жыл бұрын
There is no line 56 on this script. That error usually means you forgot to link an object to a place in the inspector.
@biseshshakya4006
@biseshshakya4006 6 жыл бұрын
Oh i researched about this and found that camera needs to be tagged maincamera but it still doesnt work!
@AsToldByWaldo
@AsToldByWaldo 6 жыл бұрын
Bisesh Shakya instead of using camera.main you can create a reference for a camera and then drag your main camera into that reference.
@MrDr3mer
@MrDr3mer 6 жыл бұрын
wow nice job.. You helped so much...thanks m8.
@devdop2046
@devdop2046 4 жыл бұрын
Short Clear and Powerful!
@YayapipiStudio
@YayapipiStudio 2 жыл бұрын
simple and great !
@ИванУспенский-ж1х
@ИванУспенский-ж1х 3 жыл бұрын
Thank you! Works great :)
@davejones8956
@davejones8956 6 жыл бұрын
I am trying to find the most effective way to toggle between pinch to zoom and pan or pinch to zoom and rotate in a 3D game in unity. Would it be possible for you to do a tutorial on this?
@AsToldByWaldo
@AsToldByWaldo 6 жыл бұрын
Dave Jones I would always keep one finger set for pan. Two fingers can easily be used for zoom or rotate. To implement the rotate I would just calculate how much the fingers have circled around a focus point. Think about how Google maps does their touch gestures.
@davejones8956
@davejones8956 6 жыл бұрын
Thnanks for your reply. If that's the case I was wondering if you could do a tutorial on how to access Public variables from one scene whilst in another scene?
@AsToldByWaldo
@AsToldByWaldo 6 жыл бұрын
It's actually rather easy and I plan to make a whole tutorial about this, but it might be months before it's released. In the meantime, just save the variable to a PlayerPrefs variable: docs.unity3d.com/ScriptReference/PlayerPrefs.html You would basically save the variable using SET like this: PlayerPrefs.SetInt("highestScore", [value]); And retrieve it in the other scene using GET like this: PlayerPrefs.GetInt("highestScore"); Use SET/GET for Int, Float & String: SetString/GetString, etc.
@coldbyte
@coldbyte 3 жыл бұрын
awesome tutorial thanks
@rickyrinaldy4885
@rickyrinaldy4885 6 жыл бұрын
how to zoom UI image in canvas, icant zoom it
@AsToldByWaldo
@AsToldByWaldo 6 жыл бұрын
Select your Canvas and change the Render Mode to World Space.
@rickyrinaldy4885
@rickyrinaldy4885 6 жыл бұрын
Doesn't work sir, can u make tutorial
@AsToldByWaldo
@AsToldByWaldo 6 жыл бұрын
It works. Use the code I provided. Adjust your canvas in the inspector to set Render Mode to "World Space" then adjust the sorting layer and move the canvas so the image is in view. Then you should be able to zoom and pan anything in the canvas including a UI image.
@_inpeymus3603
@_inpeymus3603 6 жыл бұрын
what if i dont want it in a world space?
@AsToldByWaldo
@AsToldByWaldo 6 жыл бұрын
Why wouldn't you?
@AlexandruMarean
@AlexandruMarean 5 жыл бұрын
For me, Camera.main not working.."CAmera dose not contain a definition for "main". I tagged my camera as "MainCamera" but still not working..help ?
@theeeblack0wl
@theeeblack0wl 5 жыл бұрын
Just tag it as Main Camera
@arieljr.atienza6945
@arieljr.atienza6945 5 жыл бұрын
working for me in 3d. , but how may i limit the direction of camera to prevent it to move outside of my plane. THANK YOU ^_^ ♥
@Roadified
@Roadified 4 жыл бұрын
Limit it, ether with "if else", or Mathf.Clamp(currentValue, minValue, maxValue)
@nizaralhamid4563
@nizaralhamid4563 5 жыл бұрын
thanks for the awssome tut buddy
@amirhamzaozi2205
@amirhamzaozi2205 2 жыл бұрын
thanks very helpful
@iancabss
@iancabss 6 жыл бұрын
Can this work to 3D? Can You make Pan, Zoom and Rotate for 3D?
@AsToldByWaldo
@AsToldByWaldo 6 жыл бұрын
Marc Ian Cabawatan technically yes it’ll work as long as the camera is orthographic. You could use three fingers to rotate.
@iancabss
@iancabss 6 жыл бұрын
3 fingers did'nt work. Do I have to add some code? I Dont have any knowledge from C#. But it seems good on 3D only it moves from 2D only. Zoom, Pan only.
@AsToldByWaldo
@AsToldByWaldo 6 жыл бұрын
Marc Ian Cabawatan yes you have to code the rotation element in it. I was just suggesting that 3 or even four fingers could be used as a gesture for rotation. Where one finger is for panning two is for zooming.
@ivanlim170
@ivanlim170 6 жыл бұрын
bro i just copy the code on the first part the pan around the screen but it didnt work NullReferenceException: Object reference not set to an instance of an object PanZoom.Update () (at Assets/PanZoom.cs:19)
@pressstart6864
@pressstart6864 6 жыл бұрын
Might be because you don't have a main camera. Create a reference for your camera up top like: public Camera cam; then change the line to this: touchStart = cam.ScreenToWorldPoint(Input.mousePosition); then in Unity, drag your camera into the inspector for the field "cam". Works just the same
@ivanlim170
@ivanlim170 6 жыл бұрын
@@pressstart6864 this save me lives because im doing my thesis for an mobile application but my school didn't teach us to code for mobapp even a hello world. thanks i subscribe to this channel
@ivanlim170
@ivanlim170 6 жыл бұрын
@@pressstart6864 is there any way to make this work on a perspective projection not on orthographic projection???? if there is can you help mo or something????
@emiljonsson3600
@emiljonsson3600 6 жыл бұрын
I get a similar error message but for a different part of of the script: NullReferenceException: Object reference not set to an instance of an object PanZoom.zoom (System.Single increment) (at Assets/Scripts/PanZoom.cs:44) PanZoom.Update () (at Assets/Scripts/PanZoom.cs:39) Im new to this so i don't have a clue what im doing wrong?? do you have an idea @Press Start ?
@mandarxsalvi
@mandarxsalvi 3 жыл бұрын
thanks helped alot!
@strangerguy323
@strangerguy323 3 жыл бұрын
Thank you soooooo much
@Imperial_Dynamics
@Imperial_Dynamics 4 жыл бұрын
amazing video. Thanks
@rayankheloufi3621
@rayankheloufi3621 4 жыл бұрын
Thank you so much !!
@KappaXBeta
@KappaXBeta 5 жыл бұрын
thanks, right to the point not more not less :)
@ufukguney1998
@ufukguney1998 6 жыл бұрын
is panning working on phone
@piotrkot4137
@piotrkot4137 5 жыл бұрын
Great tutorial ! Does anybody knows how to prevent from moving around to the infinity? For example, I have a background and want to prevent moving camera out of its bounds :)
@abhijitroy3180
@abhijitroy3180 5 жыл бұрын
Add camera boundaries to it.
@ccbelan3156
@ccbelan3156 4 жыл бұрын
How to add a camera boundary?
@tellosoft
@tellosoft 5 жыл бұрын
Awesome Thanks!
@dhudd3
@dhudd3 5 жыл бұрын
perfect used this in my project saved tons of time :)
@arihantparsoya
@arihantparsoya 4 жыл бұрын
Thank You!
@Jacky-fb4th
@Jacky-fb4th 3 жыл бұрын
thanks help lot
@azmanbarraquias1681
@azmanbarraquias1681 6 жыл бұрын
thanks man
@luanmonteiro2206
@luanmonteiro2206 6 жыл бұрын
Okay this works perfect for a 2d game(orthographic camera), but I'm trying to figure out how to do it in a 3d game(perspective camera), I searched the whole internet for a answer, but I didn't find. Could you do a video teaching how to do that.
@AsToldByWaldo
@AsToldByWaldo 6 жыл бұрын
Luan Monteiro it doesn’t work for perspective because ScreenToWorldPoint doesn’t work. You’d need to follow this answer here to calculate where the finger is pressing on the screen: answers.unity.com/questions/566519/camerascreentoworldpoint-in-perspective.html Then, technically it should work. Or just get rid of screen to world point and just use Mouse position.
@AsToldByWaldo
@AsToldByWaldo 6 жыл бұрын
Then for zoom, change orthographic size to field of view.
@NoName-kh5id
@NoName-kh5id 6 жыл бұрын
Thanks for the awesome tutorial! I only can't figure out how to force the camera to only move on the X axis. could someone help me with that? also, if there is an easy way to limit movement between for example 0 and 1000 on the X axis I would be very glad to know
@lehuynhquan8642
@lehuynhquan8642 6 жыл бұрын
You are so cool!
@Frwager1998
@Frwager1998 3 жыл бұрын
Make sure you don't use Camera.main in the update function, it's very slow. Set it to a variable in start
@ВладиславДенис-б9ц
@ВладиславДенис-б9ц 3 жыл бұрын
God i love you.
@burakakbal5250
@burakakbal5250 4 жыл бұрын
Awesome, but i add something to your code. In your code you have to relase your two fingers same time. // Define isInZoom variable. private bool isInZoom; ------------------------------------------- // Replace this code touchStart = Camera.main.ScreenToWorldPoint(Input.mousePosition); // To this code if (!isInZoom) touchStart = Camera.main.ScreenToWorldPoint(Input.mousePosition); ------------------------------------------- ------------------------------------------- // Add this inside if statement (Input.touchCount == 2) isInZoom = true; ----------------------------------------- ----------------------------------------- // Replace Vector3 direction = touchStart - Camera.main.ScreenToWorldPoint(Input.mousePosition); Camera.main.transform.position += direction; // To if (!isInZoom) { Vector3 direction = touchStart - Camera.main.ScreenToWorldPoint(Input.mousePosition); Camera.main.transform.position += direction; } ---------------------------------------- ---------------------------------------- // At the end of the update code add this line. if (Input.touchCount == 0) isInZoom = false; ----------------------------------------- // Also not Camera.main is an expensive way to find camera. // What i recomend is set Camera.main to a variable in start.
@wellpdoclube
@wellpdoclube 4 жыл бұрын
You still alive? how I can do to zoom with de scrool of mouse?
@wellpdoclube
@wellpdoclube 4 жыл бұрын
Sorry, eu não tinha visto o vídeo todo kskdska
@pascalmoller6097
@pascalmoller6097 4 жыл бұрын
I usually don't comment videos but I have to make an exception here as I seriously can't understand how someone could possible be ok with this code. On the plus side the tutorial is very well performed. However, the code is easily written but horrible to understand. When I first used this code I was struggling with line 19 and 20. Vector3 direction = touchStart - Camera.main.ScreenToWorldPoint(Input.mousePosition); From my intial understanding touchStart is taken once on mouse down and you are taking the current position of the mouse on each frame while the mouse button is held down. Hence this would actually result in a direction vector with increasing magnitude. Therefore I was expecting the pan motion to speed up as your are using Camera.main.transform.position += direction; which is clearly accumulating the direction vector. However the motion appears to be constant and not linear increasing which took a while for me to understand whats going on here. So since the actual hit point of ScreenToWorld Point Function is almost not moving at all due to the motion of the camera, line 19 results in a constant distance and therefore your code works. You are actually mixing camera motion with touch motion in a way that makes the code more complicated, technically you are introducing a zero-sum expression, leading to a situation where one has a hard time to actually enhance your code.
Pan, Zoom and limit camera movement - Unity 2D Tutorial
14:53
Shack Man
Рет қаралды 66 М.
Unity3D/2D: Mobile Joystick Tutorial [NO PLUGINS]
10:17
Waldo
Рет қаралды 96 М.
Арыстанның айқасы, Тәуіржанның шайқасы!
25:51
QosLike / ҚосЛайк / Косылайық
Рет қаралды 700 М.
Сестра обхитрила!
00:17
Victoria Portfolio
Рет қаралды 958 М.
Don’t Choose The Wrong Box 😱
00:41
Topper Guild
Рет қаралды 62 МЛН
TOUCH CONTROLS in Unity!
16:09
Brackeys
Рет қаралды 1,3 МЛН
Understanding Orthographic Size in Unity
6:14
Press Start
Рет қаралды 86 М.
Why you should use code to animate your UI in Unity.
5:02
Game Dev Guide
Рет қаралды 336 М.
Pinch and Scroll to Move and Zoom in Unity for Mobile Games
13:19
Creating a Custom Tab System in Unity
13:45
Game Dev Guide
Рет қаралды 238 М.
How To Build An Event System in Unity
8:01
Game Dev Guide
Рет қаралды 417 М.
2D Lights in Unity!
13:46
Brackeys
Рет қаралды 645 М.
HOW TO MAKE COOL TRAIL EFFECTS - UNITY TUTORIAL
10:38
Blackthornprod
Рет қаралды 327 М.
Making UI That Looks Good In Unity
18:06
Game Dev Guide
Рет қаралды 697 М.
Арыстанның айқасы, Тәуіржанның шайқасы!
25:51
QosLike / ҚосЛайк / Косылайық
Рет қаралды 700 М.