Book Image

Panda3D 1.7 Game Developer's Cookbook

Book Image

Panda3D 1.7 Game Developer's Cookbook

Overview of this book

Table of Contents (20 chapters)
Panda3D 1.7 Game Developer's Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Making the camera smoothly follow an object


In this recipe you will learn how to program a simple camera system that follows an object smoothly, without giving the impression of being glued to the back of the target.

Getting ready

See the recipe Setting up the game structure to create the basic application framework for the following steps.

How to do it...

Let's build a third person camera system:

  1. Add this code to Application.py:

    from direct.showbase.ShowBase import ShowBase
    from direct.actor.Actor import Actor
    from panda3d.core import Vec3
    from direct.interval.IntervalGlobal import *
    from FollowCam import FollowCam
    
    class Application(ShowBase):
        def __init__(self):
            ShowBase.__init__(self)
    
            self.world = loader.loadModel("environment")
            self.world.reparentTo(render)
            self.world.setScale(0.5)
            self.world.setPos(-8, 80, 0)
    
            self.panda = Actor("panda", {"walk": "panda-walk"})
            self.panda.reparentTo(render)
            self.panda.setHpr(270, 0, 0)...