CODING EXERSIZE: Slow-parent like rotation on top of an existing camera setup

First off, go to this thread and download my game off of the first post
http://blenderartists.org/forum/showthread.php?t=164708

Now go the scripts window and look at the script ‘main’ beyond the comment showing the camera precursor part of the script, I’ve been trying to get a good automatic camera setup for my game and for the most part it works, but I believe that the last piece of the puzzle is something to do with camera orientation as the car rotates.

Here’s the excersize, I have done most of the work for the camera system, but I don’t know how I could get a slow parent effect for rotation on top of the current system, in other words, as the car rotates, the camera moves to get behind it in a certain programmer-defined speed.

The size of the circle it would ideally rotate on would be entirely dependent on distance the car is to the camera when using only the X,Y plane, and the camera would do a slow-parent like rotation on an imaginary X,Y plane. The total number of objects in the setup would ideally not be increased and if possible have it all in the ‘main’ script.

I figure I may have to use things like matrices and I’ve never been able to understand those, so as someone who has been honestly trying to figure it out before asking, can someone help please?:slight_smile:

I’ve done that same thing one or two weeks ago. It’s very simple. You just need to have a delta of the camera movement and apply that delta slowly. For that you record the position of the camera whenever it changes then you apply the difference slowly with p = ( newposition - oldposition ) / slow_parent_speed.

This is the code I’m using:


    oldcampos = camera.worldPosition
    newcampos = char.getWorldCamPos()
    
    if newcampos != oldcampos:
        p = camera.worldPosition
        p[0] += (newcampos[0] - oldcampos[0])/CAM_SLOW_PARENT
        p[1] += (newcampos[1] - oldcampos[1])/CAM_SLOW_PARENT
        p[2] += (newcampos[2] - oldcampos[2])/CAM_SLOW_PARENT
        camera.worldPosition = p

char.getWorldCamPos() is a function I wrote that will return an internal value of the character containing where the camera should be at. CAM_SLOW_PARENT is a constant with the slow parenting speed, it’s the number of ticks it takes for the camera to take place.

If you wanna see it in action, you can download the last version I uploaded and look at char/ball2/scripts/camera.py:
http://www.vibrunazo.net/temp/testengine05.7z