Quantcast
Viewing all articles
Browse latest Browse all 154

Click hold/drag move camera

Hello Unity peeps, I'm pretty new at Unity and I'm trying to develop my first game. I've completed the course on lynda.com on Unity and I have a basic understanding of the software. I'm a web developer and I'm seasoned in PHP and Javascript so I use Javascript for my language in Unity. What I'm trying to create is game where the 3rd person army crawls across a plane. Here's what I have: It's a plane with a camera facing it on orthographic mode. I have rocks (spheres) where you will click and drag down and it will pull the 3rd person along. So, I need the camera to go the exact opposite way the user is dragging. When you click and drag the camera exposes more area ahead with more rocks and you will grab the next one with the opposite hand on the 3rd person rock to rock to rock. Here's what I understand I need so far: When I click that rock, I need to transfer from screen to world. I need the starting position of the rock click. This is the first problem I encountered. How do I get that first position? I can get the x and y position of the camera but it changes as it moves. How do I capture the very first point of the cameras position and save it in a variable to use? I figure as the user drags down on the screen, the position of the mouse can be reversed and put into the camera so it goes the exact opposite way. Any pointers in the right direction would help me out so much. I will post the update function I have right now in my click.js file on each of the spheres (rocks). function Update () { if (Input.GetMouseButtonDown(0)) { var mousePos = Input.mousePosition; var cam = camera.main; var v = cam.ScreenToWorldPoint(Vector3(mousePos.x, mousePos.y, cam.nearClipPlane)); Debug.Log(v.y); Camera.main.transform.position.y = v.y; }

Viewing all articles
Browse latest Browse all 154

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>