Mouse-Walking on a Simple Plane

Started by AGP, October 23, 2018, 06:59:02 AM

Previous topic - Next topic

AGP

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:


     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

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

Should the above code work? Am I forgetting anything?

EgonOlsen

Looks ok to me at first glance. Is this what works with multi-polygon planes? Then it will work with 2 polygonal planes as well if it's able to detect the actual collision/intersection, which depends on the offset setting mentioned above.