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

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
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;
     }

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12298
    • View Profile
    • http://www.jpct.net
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.

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12298
    • View Profile
    • http://www.jpct.net
Re: Mouse-Walking on a Simple Plane
« Reply #3 on: October 24, 2018, 08:21:23 am »
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.