### Author Topic: Mouse-Walking on a Simple Plane  (Read 2908 times)

#### AGP

• Posts: 1726
##### Mouse-Walking on a Simple Plane
« on: October 23, 2018, 06:59:02 am »
I've made three dozen attempts. I have had success on a plane with multiple polygons, but I'd like to make it work on a large plane with only two triangles. My best (unsuccesful) attempt:

Code: [Select]
`     public void mouseClicked(MouseEvent e) {        moveByMouse(e.getX(), e.getY());     }     private void moveByMouse(int mouseX, int mouseY) {//WALKBYMOUSE; CALLED ONCE TO SETUP THE WALK DIRECTION SimpleVector ray = Interact2D.reproject2D3DWS(camera, buffer, mouseX, mouseY); if (ray != null) {      SimpleVector norm = ray.normalize();      float f = theWorld.calcMinDistance(camera.getPosition(), norm, 1000);      if (1==1/*f != Object3D.COLLISION_NONE*/) { SimpleVector offset = new SimpleVector(norm); norm.scalarMul(f); norm = norm.calcSub(offset); origin = hero.getRoot().getTransformedCenter(); SimpleVector destination = new SimpleVector(norm); destination.x += camera.getPosition().x; destination.z += camera.getPosition().z; destination.y = origin.y; // Make y the same as for the hero to avoid moving up/down. hero.getRoot().setRotationMatrix(destination.calcSub(origin).getRotationMatrix()); this.destination = new SimpleVector(destination);      } } go = true;     }`

#### EgonOlsen

• Posts: 12295
##### Re: Mouse-Walking on a Simple Plane
« Reply #1 on: October 23, 2018, 08:39:16 am »
The same method that works on planes with multiple polygons will work on planes with two polygons. The logic is the same, but you might have to adjust Config.collideOffset to some higher value.

#### AGP

• Posts: 1726
##### Re: Mouse-Walking on a Simple Plane
« Reply #2 on: October 23, 2018, 07:14:50 pm »
Should the above code work? Am I forgetting anything?