• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by $$anonymous$$ · Sep 17, 2019 at 08:52 PM · cameracamera.main

Can anyone explain what the camera is doing?

I'm creating a scene where I can grab parts for building a character and just as I finished how I want my camera set up I noticed something weird. The object I have grabbed when pulled towards the camera, splits in 2. Can anyone explain why its doing this or how to fix it?

Here is a GIF I made of it happening. https://gyazo.com/d8fa629b5555dbe36db607a55a3e888e

This script is on every object I want to move with the mouse

Here is the specific code that deals with camera movement by scrollwheel

 public Vector3 diff;
 public float distanceWanted;
     
 diff = Camera.main.transform.position - transform.position; 
 float curCameraDistance = Input.GetAxis("Mouse ScrollWheel");  
 transform.position = GetMouseWorldPos() + diff.normalized * distanceWanted;
 
 if (curCameraDistance < 0f)
         {
             distanceWanted++;
         }
 else if (curCameraDistance > 0f)
         {
             distanceWanted--;
         }
 


Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by $$anonymous$$ · Sep 18, 2019 at 08:03 AM

Hey guys so I ended up solving this... It seems I am too persistent. I just ended up redoing my code (4 different ways) and got to this point. Here's the code if you were interested. Just a reminder to anyone who uses this. This script is on each GameObject you want to move.

 //Set for base starting distance (Will be changed using scrollwheel)
 public float distanceWanted = 30f;
 
 //While the mouse is held down
     private void OnMouseDrag()
     {
         //For scrolling
         float curCameraDistance = Input.GetAxis("Mouse ScrollWheel");
 
         if (curCameraDistance > 0f)
         {
             distanceWanted++;
         }
         else if (curCameraDistance < 0f)
         {
             distanceWanted--;
         }
 
         Vector3 mousePosition = new Vector3(Input.mousePosition.x, Input.mousePosition.y, distanceWanted);
         Vector3 objPos = Camera.main.ScreenToWorldPoint(mousePosition);
 
         transform.position = objPos;    
     }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Arano · Sep 18, 2019 at 08:21 AM

not 100% sure this is happening but it looks like you are going over "0" with your movement, effectively your block is trying to move from 1 to -1 each frame because you keep moving it 'towards' the camera and overshooting the 0 mark. u might want add some boundaries to your script to stop this from happening, have the movement stop when 'minDistance' is reached.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Arano · Sep 18, 2019 at 08:22 AM 0
Share

0 is the camera position (so this might not be 0,0,0) but explaining it with 1 , -1 and 0 will make most sense i think.

avatar image $$anonymous$$ · Sep 18, 2019 at 06:20 PM 0
Share

I tested that and the object was still about 10 unity units from the near plane of the camera when it happened. I think your on the right path though that it might somehow have been trying to move the object in between 2 points for some reason.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

174 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

how to switch camera 2 Answers

MainCamera just showing Skybox, when switching to Android 0 Answers

Full screen camera missing? 3 Answers

I have a main camera and another camera but in the game view i see the camera not main camera why ? 1 Answer

Camera Follow (Not Exact) 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges