1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Resource Move camera to coordinate with mouse wheel

Discussion in 'Tutorials & Resources' started by Obliviatum, Jul 14, 2018.

  1. Obliviatum

    Joined:
    Jun 30, 2018
    Messages:
    1
    Likes Received:
    1
    So I saw this code, but I thought it could be better. With this camera function you can give a Coordinate of a Npc, Object or just a random coordinate to watch. It determines the viewing angle within respect to the player and what the current viewing angle is, after which the mouse wheel makes the correction. The code can be improved a lot, but I'm happy in how it works now. I just want to share this method so you can give your own swing to it. I am also curious what you think.

    Code (Javascript):
    1. if (target.distanceTo(player.getPosition())>5 || !target.isVisible()) { //turn camera to target
    2.        if (Random.nextBoolean()){
    3.               mouseWheelTurnTo(target.getPosition());
    4.        } else {
    5.               Camera.concurrentlyTurnTo(target);
    6.        }
    7. }
    Code (Javascript):
    1. private static void mouseWheelTurnTo(Coordinate Tc){
    2.         if ( Tc == null ) return;
    3.         Player player = Players.getLocal();
    4.         Coordinate Pc = player.getPosition();
    5.  
    6.         int Dx = Tc.getX() - Pc.getX();
    7.         int Dy = Tc.getY() - Pc.getY();
    8.         int Yaw = Camera.getYaw();
    9.  
    10.         int Beta = (int)( Math.atan2( - Dx, Dy ) * 180 / Math.PI ); //atan2 is in radians so 180/PI wil transform it to degrees, like the game.
    11.         if ( Beta < 0 ) Beta = 360 + Beta;
    12.  
    13.         int deltaYaw = Beta - Yaw;
    14.  
    15.         if ( deltaYaw > 180 ) {
    16.             deltaYaw = deltaYaw - 360;
    17.         } else if ( deltaYaw < - 180 ) {
    18.             deltaYaw = deltaYaw + 360;
    19.         }
    20.  
    21.         int deltaMouseMoveX = (int) (-deltaYaw*2.5);
    22.  
    23.         Area hoverArea = new Area.Circular(Players.getLocal().getPosition(), 3);
    24.         hoverArea.getRandomCoordinate().hover();
    25.  
    26.         Mouse.press(Mouse.Button.WHEEL);
    27.         Mouse.move(new InteractablePoint((int) (Mouse.getPosition().getX() + deltaMouseMoveX), (int) (Mouse.getPosition().getY() + Random.nextInt(-10,10))));
    28.         Mouse.release(Mouse.Button.WHEEL);
    29.     }
     
    #1 Obliviatum, Jul 14, 2018
    Last edited: Jul 14, 2018
    Tbagstealer likes this.
  2. LogicScriptPro

    Joined:
    Nov 14, 2016
    Messages:
    6
    Likes Received:
    0
    @tyb51 anychance this can be implemented into VisualRM. Boy would this make things great. Thanks for the share Obliviatum
     

Share This Page

Loading...