Hello,
I am trying to reproduce a “League of Legends” camera or the camera most strategic games use. I have difficulty thinking a way for the following part:
-When my mouse cursor is near 1 of the 4 edges that form the camera and the user pushes the mouse cursor towards that direction, the camera should move accordingly.
Add 4 cubes with static physics and ghost enabled on each edge of camera(as close to camera as you can) so thy represent the place where, when cursor is hovered, camera moves. Make them invisible and parent to camera! Than make mouse over sensor, and controller for each of them and than hold down SHIFT and R click camera and add motion actuator to camera. Connect the and controller from cube to camera’s motion actuator. Do it for each of cubes. This way it will work. make sure so camera’s motion is global if your camera isn’t in stright angle so it doesn’t go too high when moving forwards or too low when going backwards;)
Gonna play with what you suggested, but I think if I zoom in our out (with the lens attribute) it is gonna get messed up. Nevertheless gonna try it. Thanks!
Yes , I 've tried it and it worked nicely. But I wanted to use the camera’s lens. I guess if I can’t link the lens with the other movement of the camera that I want to do, then I’ll go back to the z axis.
Use Python to get the distance from the mouse cursor to each of the edges of the screen. The mouse.position list should help you with this. EDIT: Or use a GUI scene with objects on the edges that you can detect mouse over events on.
I strongly suggest to use an overlay scene that contains the sensing objects.
It will be game scene independent (it does not matter where the game scene camera is or how it looks at the scene).
It will prevent any conflicts with other objects in your game.
You can make them even visible (e.g. semi-transparent).
This even allows a Python-less solution (just send messages).
Using messages allows you to moving with keyboard keys too.
@@guramarx I have no problem there.There is an option for the lens’s float number too.
@@Monster Nice idea if I decide to go with the “moving to z axis” for zoom out/in.
@@SolarLune
I used the mouse.position and the (x,y) vector that it returns.
In my example, every time I run the game, I run it from a top view. So I was moving the mouse and printing its position. The values for x and y I saw are not blender units or meters. When running the game I noticed that it was propably counting pixels where (0.0) was the top left and the bottom right was 1920 x almost 1080. So I guess it depends on the screen resolution of the game but the cool thing is it does not change when I play with the lens’s float value so I can work with that. I am going into the counting distance that you mentioned now. Although If the camera of the game would be the screen resolution itself I guess I just have to pick a number of pixels to every edge to decide when they 'll activate the effect. Will keep this post updated.
[TABLE=“class: docutils field-list”]
[TR=“class: field-odd field”]
[/TR]
[/TABLE]
Update 1: It worked with the first try :yes:. Gonna go on and play with it more.
Use mouse.position along with render.getWindowHeight() & getWindowWidth(), which gives you pixel values of the game window’s dimensions. Then you can get a ratio of how far the mouse cursor is to each edge of the screen.
mousePos = mouse.position
mX = mousePos.x / render.getWindowWidth()
mY = mousePos.y / render.getWindowHeight()
if mX < 0.05:
#mouse is on the left 5% of the screen: slide left
elif mX > 0.95:
#mouse is on the right 5% of the screen: slide right
if mY < 0.05:
#mouse is on the top 5% of the screen: slide up
elif mY > 0.95:
#mouse is on the bottom 5% of the screen: slide down
The speed of camera slide could also be affected by the edge’s counter-axis, so if you’re on the left/right edge, you also slide up/down based on mY, and vice-versa.
1)The mX and mY or the mouse.position itself are being printed at least 2 times with the max of 3 times, when I move the mouse in my screen.Is it due to the speed of the module executed? Does it happen fast and it draws the numbers faster than my movement of the mouse?If that was the case I guess it should have been many more times and not just 2 or 3. Any ideas?
2)When I am in the 5% areas it moves as intented. But it stops if I stop movement of the mouse. Even if I am still in those areas. I placed an always sensor and even put true pulse trigger to the mouse movement sensor. Nothing changed. I am pretty sure though that the code is very clear so I guess the mistake is on when the python controller is triggered. I have only 3 sensors connected to the controller. 2 mouse sensors for wheel up and down and one mouse movement sensor. Any ideas here?
Doing some experiementation, it appears that logic.mouse.position returns a float between 0.0 and 1.0, not a implicit pixel position. So no need to divide by the screen size! It’s been a while since I’ve actually dug into the mouse.position function… cam_edge_slide_test.blend (573 KB)
Here is a little test I threw together. The math for determining movement speed is pretty hacky, and diagonal movement feels kind of weird, but it functions.
I think your movement stops when you stop the mouse, because your script is being triggered by mouse movement. No mouse movement = no trigger = no script run = no movement.
You want the positive pulse ON on your Always sensor. You don’t need a mouse movement sensor for this to work (unless you’re using that for something else).
Well as mouse I used this : mouse = cont.sensors[“mouse”] , where I had named mouse a mouse movement sensor, and mouse.position returned a list of pixels. Maybe it was a mix of the command mouse.position and the sensor I had , but it worked. Nevertheless your .blend file has way neater results. Gonna play with that. Thanks!
With Mouse being a Mouse movement sensor, it does return pixel values – it’s position relative to the top-left corner of the game window. So I see where things could get mixed up.
Ok here is the .blend file with the module that I created. It is beginner friendly with comments etc. and I 'll improve it with functions after I am done. My question is the following,
when I hold middle mouse click and rotate the camera, I get close to the edges where it should move as per lines 26 to 44 but instead it uses local velocity or something that I perceived as local velocity. Why is that? Un-rotated it works fine. Any thoughts here?