unity3d - Using Accelometer in unity,to move a gameobject with in the scene -
i placing 2 gameobjects @ left down corner , right upper of screen. using 2 gameobjects form border. , using boundaries class create bound such stop pivot point of gameobject , move inside bound using accelometer (it means have 2 borders, outer border , inner border, drawing inner border using bounds width , height calculating formula derived).
this code
void start () { valueofheight = (screen.height * 110 )/ 320; valueofwidth = (screen.width * 110 )/ 480; boundaries = new bounds (new vector3(screen.width/2,screen.height/2,0f),new vector3(screen.width - valueofwidth,screen.height - valueofheight,0f)); } void update () { if(gameobject.transform.position.x > cornerpoints [1].transform.position.x && gameobject.transform.position.x < cornerpoints [3].transform.position.x&& gameobject.transform.position.y > cornerpoints [1].transform.position.y&& gameobject.transform.position.y < cornerpoints [3].transform.position.y) { debug.log("1"); gameobject.transform.position = boundaries.closestpoint(gameobject.transform.position); if (boundaries.contains (gameobject.transform.position)) { debug.log("2"); direction = new vector3 ((input.acceleration.x), (input.acceleration.y), 0); }
but problem here gameobject jerking on 1 side of border (mostly left side).if problem occurs on sides means,my code wrong.but occuring on left side of border , checked logs,(i kept logs 1 , 2),see when gameobejct comes left side of border,its 1 executing looking jerking.but not happening on sides.so want know why? in advance.
Comments
Post a Comment