(Yet another) Terrain Algorithm

I also am using the static geometry, but that would be
good maybe to mix them in the long run.
With the camera I’m trying to have a first person view
and at least one other view, like resident evil 4.
Three views would be great! I just read all the camera
topics on the forum yesterday, so I’m getting an idea
of what i need to do. I added the self accepts key [cam view]
and tried to define the new camera, but it just locked everything up,
as in the definition I just put in a completely new set of key commands :slight_smile:
I just started Panda last week.
I’m going to study the texture swapping animated duck tutorial,
so I have a very basic idea, but I think I might need alternate
cameras with different control schemes,
like the following camera scheme, because fps view might
not work very good with a third person avatar.
Usually it takes me a day to figure each new thing out,
so by tonight or tomorrow I’ll be nuts, but I’ll have 2 or 3 cameras :slight_smile:
Thanks in advance for any insight.

Don’t know Resident Evil 4, sorry, but this is what I use as camera code most of the time. It’s a combined third-person/first-person camera, with tracking (follows the NP movement, but slightly delayed).

Switching from first-person to third-person mode and back is done by setting the camera distance. If the distance is the minimum distance the code swaps to first-person. SetDistance could be tied e.g. to the mouse wheel.

Oh, and call tracking.updateMethod( ) once a frame to move the camera.

enn0x

class Tracking:

    def __init__( self, np ):
        self.np = np

        self.resilience = 8.0
        self.pitch = 0.0
        self.distance = 10.0

        self.updateMethod = self.updateThirdPerson

        self.target = render.attachNewNode( 'cameraTarget' )
        self.target.reparentTo( self.np )
        self.target.setPos( 0, 0, 0.8 )

        self.tracking = render.attachNewNode( 'cameraTracking' )
        self.tracking.reparentTo( render )
        self.tracking.setPos( self.target, 0, 0, 0 )

        base.camera.reparentTo( self.tracking )
        base.camera.setPos( 0, -self.distance, 0 )
        base.camera.lookAt( 0, 0, 0 )

    def release( self ):
        self.target.removeNode( )
        self.tracking.removeNode( )

        base.camera.reparentTo( render )

    def setPitch( self, delta ):
        self.pitch += delta
        self.pitch = clampScalar( self.pitch, -70.0, 70.0 )

    def setCameraDistance( self, factor ):
        self.distance *= factor
        self.distance = clampScalar( self.distance, 2.0, 400.0 )

        if self.distance == 2.0:
            self.updateMethod = self.updateFirstPerson
            base.camera.setPos( 0, 0, 0 )
            self.np.hide( )
        else:
            self.updateMethod = self.updateThirdPerson
            base.camera.setPos( 0, -self.distance, 0 )
            self.np.show( )

    def updateThirdPerson( self, dt ):
        dt2 = min( dt * self.resilience, 0.4 )
        t = self.target.getTransform( self.tracking )

        deltaPos = t.getPos( ) * dt2
        self.tracking.setPos( self.tracking, deltaPos )

        deltaH = t.getHpr( )[0] * dt2
        self.tracking.setH( self.tracking.getH( ) + deltaH )
        self.tracking.setP( self.pitch )

    def updateFirstPerson( self, dt ):
        self.tracking.setPos( self.target, 0, 0, 0 )

        self.tracking.setH( self.np.getH( ) )
        self.tracking.setP( self.pitch )

You should rent resident evil 4 at blockbuster!
It was the game of the year last year or the year before,
and everything in it seems to be reproducible within panda .
Thanks! This is pretty concise, when I get it working I’ll
give you coding credit, and ten percent if I ever get to the
point of selling stuff (a good camera system is half the battle).
[EDIT] I should say I’ll give you ten percent if I use your
camera system, and not ten percent of everything I ever make. :open_mouth:
I don’t really see making any money with xbox and ps3 out
there though. Mainly I’m trying to impress
my family and have a videogame for my CG portfolio.
Right now I can get it to track with your code,
but my terrain is too little for me to get close enough
to slip into first person. I just hacked it into my code though,
and I don’t really know what I’m doing, but it works!

I like the mouse wheel ‘smooth zoom into first person’
approach better than ‘click instant different pov’ type.

I was looking at ‘gravitywalker’ and was a little
disheartened by its sheer length and lack of animation capabilities,
so this was awesome to find.