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

Adding ribbon trails to an object


This recipe will show you how to implement a ribbon trail effect that is often used for emphasizing high-speed movements such as sword slashes, very fast vehicles passing by or, as you will see after finishing this recipe, the fastest running panda in the world.

Getting ready

Follow the instructions of Setting up the game structure found in Chapter 1 before you proceed to create a basic project setup.

How to do it...

The following steps are necessary for implementing the ribbon trail effect:

  1. Add a new file called Ribbon.py to the project and add the following code:

    from direct.task import Task
    from direct.task.TaskManagerGlobal import taskMgr
    from panda3d.core import *
    
    class RibbonNode():
        def __init__(self, pos, damping):
            self.pos = Vec3(pos)
            self.damping = damping
            self.delta = Vec3()
    
        def update(self, pos):
            self.delta = (pos - self.pos) * self.damping
            self.pos += self.delta
    
    class Ribbon():
        def __init__(self...