Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
1
Question by UdevMike · Mar 01, 2012 at 11:57 PM · transforminputmouse position

Anomaly: Mouse Y also affects its X value. Values tied to object position.

Hey guys! I have a weird issue here that I would really like to figure out.

I have an object with a script that controls the Z position of an object.

transform.position.z = Input.mousePosition.normalized.y;

Basically this^^

It works fine when I move the mouse up and down. The weird issue is that when I move the mouse sideways, it also registers as if it was moving up and down. Why does mouse X affect the Z of my object?

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 Julien-Lynge · Mar 02, 2012 at 12:14 AM 0
Share

Your comment says what you're doing is "basically this," so it sounds like there are differences with the actual code you're running. Have you tried doing a direct output to make sure the problem isn't somewhere else in your code? $$anonymous$$g.,

 Debug.Log("$$anonymous$$ouse Y this frame is: " + Input.mousePosition.normalized.y);
avatar image syclamoth · Mar 02, 2012 at 12:19 AM 1
Share

Wait wait...

 Input.mousePosition.normalized;

As far as I can tell, this will always give you a vector pointing from the bottom-left corner of the scrween, towards where the mouse is, of length '1'. I think you should omit the normalization bit. Could you go into a bit more detail about exactly what you expect the code to do?

avatar image UdevMike · Mar 02, 2012 at 12:37 AM 0
Share

Basically I would like the mouse Y position to control the player paddle in my Pong game.

This is the exact code: paddlePosZ = -Input.mousePosition.normalized.y * -26; transform.position = new Vector3(transform.position.x,transform.position.y, paddlePosZ);

I apologize for not making myself as clear as I could. It appears that when I print to console the mouse's X value and move the mouse up and down the values change drastically, when in fact they should stay roughly the same since I am only moving it in the Y direction...

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by kevork · Mar 02, 2012 at 01:00 AM

Input.GetAxis("Mouse Y")

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 UdevMike · Mar 02, 2012 at 01:21 AM 0
Share

Same deal :/

avatar image kevork · Mar 02, 2012 at 01:29 AM 0
Share

What is the code you used? What specifically occurred that you didn't intend?

avatar image
0

Answer by Eric5h5 · Mar 02, 2012 at 01:58 AM

You don't want to use ".normalized"; that alters the entire value of mousePosition in order to make it have a magnitude of 1. It's expected behavior, not weird.

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

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.

Follow this Question

Answers Answers and Comments

8 People are following this question.

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

Related Questions

Transform.Rotate not stopping? 1 Answer

transform.LookAt gives a twist 2 Answers

Controlling parent by Inputs 1 Answer

Boolean and input relation 0 Answers

Simple AI and jump 0 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