0

I have keyframed the scale of the camera in my scene so that it always does kind of a zoom in and zoom out to an object at the beginning of the scene. Using the logic bricks I have established an "always" sensor with an "action" controller linking that specific action but it isn't working! I have read this post and tried it but still is not working. Is it even posible to do it in the BGE? I am using v 2.72

enter image description here

PAT
  • 25
  • 4

1 Answers1

0

Animating the orthographic scale the way you do it is not possible. You can however do this via python using bge.logic.getCurrentScene().objects["Your_Camera"].ortho_scale = your_value. Your_Camera has to be the name of the camera whose orthographic scale you want to adjust. your_value has to be the desired focal length. That can be a float between 0.01 and 4000.0. Following is an example of zooming in to a value of 5.0. Therefore the orthographic scale at the start needs to be above 5.0.

import bge

#getting the camera object called 'Camera' cam = bge.logic.getCurrentScene().objects["Camera"]

#while the orthografic scale is above 5.0 the script reduces it by 0.5 everytime the script controller is activated if cam.ortho_scale > 5.0: cam.ortho_scale -= 0.5

The script activated every logic tick (always sensor -> true level triggering) looks like this (it has a better frame rate of course). The starting orthographic scale is 23.0: script executed

Now you can write a script that does what you want. Here's another example where we are zooming in first and when this has finished we are zooming out again.

import bge

#getting the camera object called 'Camera' cam = bge.logic.getCurrentScene().objects["Camera"]

#while the orthografic scale is above 5.0 the script reduces it by 0.5 everytime the script controller is activated, if there's a game property with the name 'zoomed_in' it won't zoom in again if cam.ortho_scale > 5.0 and not "zoomed_in" in cam: cam.ortho_scale -= 0.5 #if the cam is already zoomed in and the ortho_scale at a value of 5.0 the camera is zooming out again, adds the game property 'zoomed_in' to the camera to prevent it from zooming in again elif cam.ortho_scale < 23.0: cam["zoomed_in"] = True cam.ortho_scale += 0.5

Here's the result: zoom in and out

palkonimo
  • 1,242
  • 1
  • 13
  • 21
  • thank you so much for taking time to provide such a complete answer! May I ask how it was possible for you to came to this result? Is there a good reference on how to achieve stuff like this? – PAT Aug 01 '16 at 20:55
  • The reference for coding stuff I use the most is bgepython.tutorialsforblender3d.com there you have almost everything you need. For example knowing that I want to modify the camera's orthographic scale I select 'camera' and look for the fitting attribute. In this case it's 'ortho_scale' . Now you have to know what to do with the information you get there. And that's something you can only learn :D – palkonimo Aug 01 '16 at 21:14