Hel Posted June 2, 2018 Share Posted June 2, 2018 (edited) @Lemons' mouse camera has a slight flaw (It's old and labelled simple, I know, but I still like it). If the entity is ever so slightly off the screen, the Camera won't move to it. The link to the thread If you can fix it, you'll be my personal favorite for at least 2 days. (may be a slight reward to any gentleman / lady to assist ) edit: also seems to happen with default camera.toEntity. as @Fruity has mentioned I could simply walk to the entity if it's > a distance, but I'd rather a better fix, as the camera can easily be tilted further down and interact w the entity. Edited June 2, 2018 by Slut Quote Link to comment Share on other sites More sharing options...
Alek Posted June 2, 2018 Share Posted June 2, 2018 The normalization doesn't look (quite) right on line 187 and 188. Change the int to a float for "angle", then normalize it with Math.atan2(Math.sin(angle), Math.cos(angle)), then you can cast this to an int. See if that works out. 1 1 Quote Link to comment Share on other sites More sharing options...
Lemons Posted June 2, 2018 Share Posted June 2, 2018 Heres the camera from my QuantumAPI, I fixed a few issues since I posted that snippet. You'll need to adapt it to work without the API but it shouldn't be hard: package rip.quantum.api; import java.awt.Point; import java.awt.event.MouseEvent; import org.osbot.rs07.api.map.Position; import org.osbot.rs07.api.model.Entity; import org.osbot.rs07.api.model.Vector3D; import org.osbot.rs07.script.MethodProvider; import rip.quantum.QuantumAPI; /** * Camera that uses the middle-mouse button and mouse movements. * * @author lemons */ public class QuantumCamera extends QuantumAPI { public QuantumCamera(MethodProvider methodProdiver) { super(methodProdiver); } /** * Moves the camera to the desired yaw and pitch. * * @param yaw * @param pitch */ public void moveCamera(int yaw, int pitch) { if (pitch > 67) pitch = 67; else if (pitch < 34) pitch = 34; int pitchCur = getPitchAngle(), yawCur = getYawAngle(), pitchDir = pitch < pitchCur ? -1 : 1, pitchDiff = Math.abs(pitch - pitchCur), yawDir = yaw > yawCur ? -1 : 1, yawDiff = Math.abs(yaw - yawCur); if (yawDiff > 180) { // Flip how we get there yawDiff = 360 - yawDiff; yawDir *= -1; } if (yawDiff < 22 && pitchDiff < 14) return; int x = yawDir * yawDiff * 3, y = pitchDir * pitchDiff * 3; int minX = 40 - (yawDir == -1 ? x : 0), maxX = 724 - (yawDir == 1 ? x : 0), minY = 40 + (pitchDir == -1 ? y : 0), maxY = 460 + (pitchDir == 1 ? y: 0); try { Point bot = getMouse().getPosition(); for (int i = 0; i < 5 && !getMouse().isOnScreen(); i++) { getMouse().move(random(minX, maxX), random(minY, maxY)); sleep(50); } if (bot.x < minX || bot.x > maxX || bot.y < minY || bot.y > maxY) { getMouse().move(random(minX, maxX), random(minY, maxY)); sleep(50); } mousePress(true); bot = getMouse().getPosition(); int newX = Math.min(764, Math.max(0, bot.x + x)), newY = Math.min(502, Math.max(0, bot.y + y)); // Use OSBots move here getMethods().getMouse().move(newX, newY); sleep(50); mousePress(false); } catch (InterruptedException e) { getLogger().error("", e); } } public boolean toEntity(Entity e) { return toEntity(myPosition(), e); } /** * Turns the camera toward the entity as if the player were positioned at origin. * @param origin * @param e * @return */ public boolean toEntity(Vector3D origin, Entity e) { if (e == null) return false; moveCamera(getAngleTo(origin, e), getPitchTo(origin, e)); return true; } /** * Turns the camera toward the tile as if the player were positioned at origin. * @param origin * @param tile * @return */ public boolean toVector3D(Vector3D origin, Vector3D tile) { if (getMap().distance(origin, myPosition()) > 16) return false; moveCamera(getAngleTo(origin, tile), getPitchTo(origin, tile)); return true; } /** * Turns the camera towards tile from the players current position. * @param tile * @return */ public boolean toVector3D(Vector3D tile) { return toVector3D(myPosition(), tile); } /** * Turns the camera towards the position from the origin. * @param tile * @return */ public boolean toPosition(Position origin, Position p) { return toVector3D(origin, p); } public boolean toPosition(Position p) { return toVector3D(p); } /** * Faces the camera roughly north. */ public void toNorth() { int r = random(0, 30); if (r > 15) r = 375 - r; getCamera().moveYaw(r); } /** * Faces the camera roughly west. */ public void toWest() { getCamera().moveYaw(75 + random(0, 30)); } /** * Faces the camera roughly south. */ public void toSouth() { getCamera().moveYaw(165 + random(0, 30)); } /** * Faces the camera roughly east. */ public void toEast() { getCamera().moveYaw(255 + random(0, 30)); } public int getLowestPitchAngle() { return getMethods().getCamera().getLowestPitchAngle(); } public int getPitchAngle() { return getMethods().getCamera().getPitchAngle(); } public int getX() { return getMethods().getCamera().getX(); } public int getY() { return getMethods().getCamera().getY(); } public int getYawAngle() { return getMethods().getCamera().getYawAngle(); } public int getZ() { return getMethods().getCamera().getZ(); } public boolean isDefaultScaleZ() { return getMethods().getCamera().isDefaultScaleZ(); } public boolean movePitch(int degrees) { moveCamera(getYawAngle(), degrees); return true; } public boolean moveYaw(int degrees) { moveCamera(degrees, getPitchAngle()); return true; } public boolean toBottom() { return movePitch(0); } public boolean toTop() { return movePitch(67); } private void mousePress(boolean press) { getBot() .getMouseEventHandler() .generateBotMouseEvent(press ? MouseEvent.MOUSE_PRESSED : MouseEvent.MOUSE_RELEASED, System.currentTimeMillis(), 0, getMouse().getPosition().x, getMouse().getPosition().y, 1, false, MouseEvent.BUTTON2, true); } private int getPitchTo(Vector3D origin, Vector3D t) { int pitch = 67 - (int) (getMap().distance(origin, t) * 4); if (pitch > 67) { pitch = 67; } else if (pitch < 22) { pitch = 22; } return pitch; } private int getAngleTo(Vector3D origin, Vector3D tile) { int degree = (int) Math.toDegrees(Math.atan2( tile.getY() - origin.getY(), tile.getX() - origin.getX())); int a = ((degree >= 0 ? degree : 360 + degree) - 90) % 360; return a < 0 ? a + 360 : a; } } 1 2 Quote Link to comment Share on other sites More sharing options...
Hel Posted June 3, 2018 Author Share Posted June 3, 2018 10 hours ago, Alek said: The normalization doesn't look (quite) right on line 187 and 188. Change the int to a float for "angle", then normalize it with Math.atan2(Math.sin(angle), Math.cos(angle)), then you can cast this to an int. See if that works out. I've noticed this also happens with your default camera. If the camera is titled at a low (pitch I think it is? Downward), but not the lowest, it sometimes has trouble tilting further down and will walk to the entity by default (As Fruity said was the fix) 7 hours ago, Lemons said: Heres the camera from my QuantumAPI, I fixed a few issues since I posted that snippet. You'll need to adapt it to work without the API but it shouldn't be hard: ty will do some testing x Quote Link to comment Share on other sites More sharing options...
Alek Posted June 3, 2018 Share Posted June 3, 2018 14 hours ago, Slut said: I've noticed this also happens with your default camera. If the camera is titled at a low (pitch I think it is? Downward), but not the lowest, it sometimes has trouble tilting further down and will walk to the entity by default (As Fruity said was the fix) ty will do some testing x Thats pitch, not yaw though. Quote Link to comment Share on other sites More sharing options...
Hel Posted June 3, 2018 Author Share Posted June 3, 2018 6 hours ago, Alek said: Thats pitch, not yaw though. i don't know the difference, one of the things I could never wrap my head around in physics lol Quote Link to comment Share on other sites More sharing options...
Alek Posted June 3, 2018 Share Posted June 3, 2018 20 minutes ago, Slut said: i don't know the difference, one of the things I could never wrap my head around in physics lol 1 Quote Link to comment Share on other sites More sharing options...
Hel Posted June 3, 2018 Author Share Posted June 3, 2018 40 minutes ago, Alek said: yea so I was talking pitch? I meant the y axis ? Quote Link to comment Share on other sites More sharing options...