0
$\begingroup$

I am trying to create a rotation system around my character so that when i hold down right mouse button and move the mouse, the camera rotates round the character and when you let go of it, the view stays where it is. Once you let go, you can use the custom mouse pointer to click on items in the scene.

I have the problem that when you rotate the camera, the pointer snaps to the center of the screen (when i want it to stay in place) and jolts the camera. I am aiming for a way to have a similar system to the game Astroneer for reference. Any idea of how i could achieve this?

$\endgroup$
  • 4
    $\begingroup$ The mouse-look sensor works by centering the mouse each frame, and measuring the amount that it rotates by. The easiest way to 'fix' this is to use a custom mouselook script that saves the mouse position when clicked, and restores the mouse position after the button is released. $\endgroup$ – sdfgeoff Jan 11 '18 at 14:05
0
$\begingroup$

I've programmed several mouselook scripts. All of them are referencing to the center of the screen which is normal. Only thing you need to do is to set the reference to where your click RMB.

EDIT: Not nice but here is an old one I modified:

from bge import logic, render

def mouselook():
 #get needed properties
 res_x = render.getWindowWidth()
 res_y = render.getWindowHeight()
 mid_x = own['mid_x']
 mid_y = own['mid_y']
 sens = 0.001

 # get rotation
 x = (mid_x-(res_x*logic.mouse.position[0]))*sens
 y = (mid_y-(res_y*logic.mouse.position[1]))/2*sens

 # look left/right
 own.applyRotation((0,0,x),False)

 # look up/down
 own.applyRotation((y,0,0),True)

 # reset mouse to center
 render.setMousePosition(mid_x , mid_y)

cont = logic.getCurrentController()
own = cont.owner
look = cont.sensors['look']
rmb = cont.sensors['rmb']

if rmb.status == 1:
 own['mid_x'] = logic.mouse.position[0] * render.getWindowWidth()
 own['mid_y'] = logic.mouse.position[1] * render.getWindowHeight()
 print(logic.mouse.position)


if look.positive and rmb.positive:
 mouselook()

Here the logics attached to the camera: logic attached to camera

$\endgroup$
  • 1
    $\begingroup$ Not a fan of the one space indenting. 4 is recommended. $\endgroup$ – batFINGER Feb 17 '18 at 11:58
  • $\begingroup$ Yeah, me too. Usually I use Tabs but as I mentioned this is a really old one. My very first beginnings of python and blender. $\endgroup$ – Richy Feb 17 '18 at 12:26
  • $\begingroup$ .. could be modified a little more IMHO. (eg 4 space tabs) $\endgroup$ – batFINGER Feb 17 '18 at 12:31
0
$\begingroup$

You need two modes/states

  • view change mode where you turn the camera with mouse movement. Typically the mouse cursor is not shown in this mode
  • click mode where you can see and move the mouse cursor. The camera is not turned by the mouse.

You need to define when to switch from one mode/state to the other

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.