- Home /
The question is answered
object falow finger problem ?
Hi : i want the object only falow the x axis and it's work but the problem with y axis it moves the object to the bottom of the screen and her is my code
if(Input.touchCount > 0)
{
//what ever i giv to the y axis it's the same result !
Vector3 pl = new Vector3(Input.GetTouch(0).position.x,0,1);
transform.position = Camera.main.ScreenToWorldPoint (pl);
}
So what is the actual problem? You set a 0 for y axis. If you want a specific y position you need to set it. Try:
Vector3 pl = new Vector3(Input.GetTouch(0).position.x, Screen.height / 2.0f, 1);
transform.position = Camera.main.ScreenToWorldPoint (pl);
(I did not test this. $$anonymous$$ight be that the values are normalized in which case you should use 0.5f ins$$anonymous$$d of "Screen.height / 2.0f").
@antx : i already mentioned //what ever i giv to the y axis it's the same result !
Answer by droni · Feb 04, 2016 at 11:12 PM
Its really simple you wrote in the code y = 0 try to use pl.transform.position.y or similar i am not really sure cant check that smartphone user :3
Answer by Nanofication · Feb 05, 2016 at 04:32 PM
I'm assuming this is a 2d game.
So some questions are, is your character zeroed out? aka. the position is (0,0,0)? If the y axis is greater than 0, then your character will move all the way to the bottom of the screen.
If not, I recommend storing your character's position in a Vector3 variable ("startPosition" for example)
and just do Vector3 pl = new Vector3(Input.GetTouch(0).position.x, startPosition.y, startPosition.z)
This is to keep your character's y and z position relative to its starting position.
Answer by Ali-hatem · Feb 04, 2016 at 10:56 AM
ok i found out the problem when i give zero to the ( y axis ) i send the object to the zero axis of the camera because that what //Camera.main.ScreenToWorldPoint
do.