- Home /
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?
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);
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?
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...
Answer by kevork · Mar 02, 2012 at 01:00 AM
What is the code you used? What specifically occurred that you didn't intend?
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.
Your answer
Follow this Question
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