ShiftedClock 3 Posted October 14, 2018 Report Share Posted October 14, 2018 Hi, how do I make a UniversalCamera rotate on mouse move without the user having to click and drag on the canvas? Sorry for such a noob question, I just can't figure it out. Thanks. Quote Link to post Share on other sites
coolroar 52 Posted October 14, 2018 Report Share Posted October 14, 2018 Hi Steven, Here is one way -- paste this into your createScene function: // other stuff ... var rotationRate = .00002, winCntrX = engine.getRenderWidth(true)/2, winCntrY = engine.getRenderHeight(true)/2; window.addEventListener("resize", function () {// in case user adjusts window engine.resize(); winCntrX = engine.getRenderWidth(true)/2, // current screen center X winCntrY = engine.getRenderHeight(true)/2; // current screen center Y }); scene.registerBeforeRender(function(){ // other stuff ... var mx = (scene.pointerX-winCntrX) * rotationRate, // get rotation increments my = -(scene.pointerY-winCntrY) * rotationRate; camera.rotation.y += mx; // increment rotation camera.rotation.x += -my; if (camera.rotation.x > Math.PI/2.2) camera.rotation.x = Math.PI/2.2; // up limit if (camera.rotation.x < -Math.PI/2.2) camera.rotation.x = -Math.PI/2.2; // down limit // other stuff ... }); Here's an example: https://www.babylonjs-playground.com/index.html#PFC6AM Have fun! 💥 Quote Link to post Share on other sites
Gijs 85 Posted October 14, 2018 Report Share Posted October 14, 2018 Hi, you can set engine.isPointerLock = true; ShiftedClock and coolroar 2 Quote Link to post Share on other sites
ShiftedClock 3 Posted October 14, 2018 Author Report Share Posted October 14, 2018 Thanks! Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.