Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • 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 /
This question was closed Dec 10, 2021 at 07:48 AM by ptr_ha for the following reason:

Problem is not reproducible or outdated

avatar image
0
Question by ptr_ha · Dec 03, 2021 at 10:03 AM · vector3transform.positioncubespheregetmousebutton

Why is my y-axis bugging?

Hi, all!

I'm currently working on an assignment from my university and can't figure this following thing out.

In my project, I have a sphere that follows my mouse. When I touch a cube, it's selected and I want to perform transformations on it. When I hold the left mouse click, I want to move the cube.

The following script comes from the update() in my sphere:

             Vector3 spherePosition = transform.position;
 
             // Modify position
             if (Input.GetMouseButton(0))
             {
                 Debug.Log("Current Sphere position: " + spherePosition);
                 selected[0].transform.position = spherePosition;
             }

The "selected" is a Cube-element.

Now the issue is that, although I'm not moving the mouse, the y-axis is acting weird every other frame. I jumps to much lower values so that I sometimes loose it in the camera fram when I let go from the left mouse click: alt text

I could not help myself with googling so thanks in advance for any tips!

unbenannt.png (59.8 kB)
Comment
Add comment · Show 3
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 CodesCove · Dec 03, 2021 at 10:23 AM 0
Share

Can you post the code where you are doing the screen space (mouse coordinates) transform to world space (the 3d space)?

avatar image ptr_ha CodesCove · Dec 03, 2021 at 01:25 PM 0
Share

Oh, maybe this could be the issue! Our tutor told us to check the script but till now I didn't know, why. :D

The current update-function from the followMouse script is the following:

 void Update()
         {
             Vector3 pos = Input.mousePosition;
             pos.z = 1;
     
             transform.position = Camera.main.ScreenToWorldPoint(pos);
         }

The camera however is not on (0, 0, 0) which is why we have a little disorted view on the games coordinate system. However, we want the sphere to actually move on the x- and y-axis from the camera-view and point into the space (z-axis). We got told that we should take a look at the "ScreenToWorldPoint"- and "LookAt"-function but this didn't help me yet.

Thanks in advance for any help!

avatar image CodesCove ptr_ha · Dec 03, 2021 at 01:53 PM 0
Share

Check first that you don't have duplicate "touch" component in scene. You can modify your debug line as follows:

 Debug.Log("Current Sphere position: " + spherePosition + " Instance ID: " + this.GetInstanceID());

If you get different instance id numbers then you have "extra" component in the scene and need to remove it.

1 Reply

  • Sort: 
avatar image
0

Answer by MarekRimal · Dec 03, 2021 at 02:17 PM

Then you have to provide the code where u are changing the sphere position. You said that it should follow the mouse, where is the code responsible for that?

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

Follow this Question

Answers Answers and Comments

165 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

Related Questions

Maping cube to sphere. Help. 1 Answer

How to carry over variable (transform.position) and use it as Vector3 for instanitating a prefab 2 Answers

How would I move an Object after collision? 1 Answer

How to reverse a sin animation? 2 Answers

How to change transform.position.x to go backwards at specific instance? 2 Answers


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