java - Moving Body using force in Libgdx based off of touch input -


what trying take in inputted user touch down, convert camera coordinates of touch down world coordinates, create vector use in order apply force body. have that:

    vector3 worldpos = new vector3(newx, newy, 0);     gamescreen.gamecam.unproject(worldpos);      newx = worldpos.x;     newy = worldpos.y;      vector2 direction = new vector2();      direction.set((newx - xpos), (newy - ypos));      if (newx <= xpos){         direction.set((xpos - newx), (ypos - newy));     }      b2body.applyforcetocenter(direction, true); 

i know isn't right @ far creating vector goes, coordinates being converted properly.

so question is, how can accurate vector, in negative direction, when have both world coordinates of body , touch down?

i have tried doing research better understanding of of having bit of trouble. appreciated, thank time.

if have on newx, newy screen touch coordinates , next change world coords can direction subtraction touchworldpos currentobjectpos:

vector3 worldpos = new vector3(newx, newy, 0); gamescreen.gamecam.unproject(worldpos);  newx = worldpos.x; newy = worldpos.y;  vector2 direction = new vector2(); direction.set((newx - xpos), (newy - ypos));   b2body.applyforcetocenter(direction, true); 

without if statement:

 if (newx <= xpos){     direction.set((xpos - newx), (ypos - newy));  } 

in box2d direction might have small values , must muliply 1 value 100(mayby more)


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -