I have a map where the player can zoom into anywere to get a closer look. i have the zooming looking the way i want it to, with one problem. if the player puts their mouse on a specific location, then begin zooming. they end up off of where the began zooming.
i need to keep the mouse on to the same relative location.
MEATHODS I HAVE TRIED:
METHOD 1:
seting an empty to the hit position before the scroll. after scroll is completed seting the mouse to be the empty’s screen position.
i also used the method as above only in stead of using an empty saving the world position, and using that.
Reasons Method 1 Failed:
mouse would not stay put when i was not zooming, it would shake around. also the position was still not correct location.
METHOD 2:
geting the screen position of a single stationary object, and moving the mouse based on the vector of the change in that objects screen position.
Reasons Method 2 Failed:
no shaking this time, but the mouse was still not in the correct location. mouse moved off target when almost zoomed in all the way.
Your code mixes pretty much things together. This makes it really hard to read. I suggest to have on controller for one purpose. (Hint: try to name the controller with one verb [+ nouns] - if you need more than one verb the controller does to much)
Trigger the controller only when needed (e.g. mouse over any + mouse key) using an always sensor triggering controllers unnecessary is wasting processing time and illogical.
I would do the zoom this way:
Zoom in:
Move the camera towards the hitPosition of the mouse over any sensor. (If there is no hitPosition, you could use the rayTarget.
Zoom out
Move the camera towards the “satellite position” of the camera (where the camera was placed originally)
Other option:
place an empty at the rayTarget of the mouse sensor
let the camera track the empty
decrease/increase the camera’s lens value
Buy moving the empty you can move the visible section of the world.
Thanks Monster Ill keep that in mind. although i was posting the .blend for a visual aid, the code was intentionaly criptic. But performance could be increased. Thanks.
that actualy is how it works. except when zooming the camera needs to only zoom with translation, not rotation. this is working. this restricts the players camera motion when zoomed in. this is to hide the scene change that will populate cities. You may have noticed this change, not very many of the countries have been set up and the default is alaska. Try zooming all the way into greenland.
the result of the translation only zoom is that the mouse gets off its target.
You just need to move toward the hitPoint. If you use rayTarget it is exactly the same direction.
You might need hitObject to do relative steps (like 10% of distance) and to limit the zoom that you can’t move behind the map.
You could zoom out the same way as zoom in, but this would make you camera be placed at a different position. I guess this is not what you want. So as you already wrote you need a “satellite” position that the camera cam move towards this position (rather than hitPoint/rayTarget).
With that method you do not need rotation. You just move the camera.
I have the zoom the way i like it though. its very smooth and effecively hides the scene change.
except when zooming the camera needs to only zoom with translation, not rotation. this is working. this restricts the players camera motion when zoomed in. this is to hide the scene change that will populate cities.
i have implemented this.
the motion of the zoom looks realy good. id rather keep that and have the weird mouse thing.
I noticed that the mouse always needed to be moved towards the middle of the screen. i tried moving the mouse towards the center every zoom click with suprising success. it helped a little but was still not there.
I really can’t fix your solution as the code is simply not clean enough to understand what it does. Obviously it does something you want but I really do not see it in a few minutes.
What I see is that it has strong dependencies to other places (e.g. properties). The code has multiple concerns not just zooming. The naming does not really support understanding (I guess you are the only one who knows what “NewCamStyle”, “ZoomPixie”, “FixMouse”, “mousemoved”, “OL”, “width” etc. means and how they belong together.) So this is pretty hard to read for others.
Have a look at the attached file. I replaced your zooming with a different one. It is separated from the other tasks of your game. You might find the code a bit over-complicated. Feel free to simplify it as much as you can :yes:.
To smooth out the camera movement, the navigation logic is applied to an empty and the camera is slow parented to this empty. I hope you are not using “Home” for anything else :spin:.
The next task would be to move “Home” left-right-up-down let the viewer slide over the map ;). This should be a simple task. It does not even need code except you want to use the mouse for a drag-and-move motion.