my FPS script awsd+jumping wall sliding

Return to Code Snippets

my FPS script awsd+jumping wall sliding

Postby treeform » Tue Apr 08, 2008 11:23 am

here is my little script i would like some code review and maybe clean it up:
------------- update ------------------
http://www.istrolid.com/p/panda3d/simple-fps.zip
------------- update ------------------
Code: Select all

import direct.directbase.DirectStart
from direct.showbase.DirectObject import DirectObject
from pandac.PandaModules import *

class FPS(object,DirectObject):
    def __init__(self):
        self.initCollision()
        self.loadLevel()
        self.initPlayer()
       
    def initCollision(self):
        #initialize traverser
        base.cTrav = CollisionTraverser()
        #initialize pusher
        self.pusher = CollisionHandlerPusher()
       
    def loadLevel(self):
       
        #load level
        # must have
        #<Group> *something* {
        #  <Collide> { Polyset keep descend } in the egg file
        level = loader.loadModel('level.egg')
        level.reparentTo(render)
        level.setPos(0,0,0)
        level.setTwoSided(True)
        level.setColor(1,1,1,.5)
               
    def initPlayer(self):
       
        #load man
        self.man = loader.loadModel('teapot')
        self.man.reparentTo(render)
        self.man.setPos(0,0,2)
        self.man.setScale(.05)
        base.camera.reparentTo(self.man)
        base.camera.setPos(0,0,0)
        base.disableMouse()
        #create a collsion solid for the man
        cNode = CollisionNode('man')
        cNode.addSolid(CollisionSphere(0,0,0,3))
        manC = self.man.attachNewNode(cNode)
        base.cTrav.addCollider(manC,self.pusher)
        self.pusher.addCollider(manC,self.man, base.drive.node())
       
        speed = 50
        Forward = Vec3(0,speed*2,0)
        Back = Vec3(0,-speed,0)
        Left = Vec3(-speed,0,0)
        Right = Vec3(speed,0,0)
        Stop = Vec3(0)
        self.walk = Stop
        self.strife = Stop
        self.jump = 0
        taskMgr.add(self.move, 'move-task')
        self.accept( "space" , self.__setattr__,["jump",1.])
        self.accept( "s" , self.__setattr__,["walk",Back] )
        self.accept( "w" , self.__setattr__,["walk",Forward])
        self.accept( "s" , self.__setattr__,["walk",Back] )
        self.accept( "s-up" , self.__setattr__,["walk",Stop] )
        self.accept( "w-up" , self.__setattr__,["walk",Stop] )
        self.accept( "a" , self.__setattr__,["strife",Left])
        self.accept( "d" , self.__setattr__,["strife",Right] )
        self.accept( "a-up" , self.__setattr__,["strife",Stop] )
        self.accept( "d-up" , self.__setattr__,["strife",Stop] )
       
        self.manGroundRay = CollisionRay()
        self.manGroundRay.setOrigin(0,0,-.2)
        self.manGroundRay.setDirection(0,0,-1)
       
        self.manGroundCol = CollisionNode('manRay')
        self.manGroundCol.addSolid(self.manGroundRay)
        self.manGroundCol.setFromCollideMask(BitMask32.bit(0))
        self.manGroundCol.setIntoCollideMask(BitMask32.allOff())
       
        self.manGroundColNp = self.man.attachNewNode(self.manGroundCol)
        self.manGroundColNp.show()
        self.manGroundHandler = CollisionHandlerQueue()
       
        base.cTrav.addCollider(self.manGroundColNp, self.manGroundHandler)
       
    def move(self,task):
       
        # mouse
        md = base.win.getPointer(0)
        x = md.getX()
        y = md.getY()
        if base.win.movePointer(0, base.win.getXSize()/2, base.win.getYSize()/2):
            self.man.setH(self.man.getH() -  (x - base.win.getXSize()/2)*0.1)
            base.camera.setP(base.camera.getP() - (y - base.win.getYSize()/2)*0.1)
        # move where the keys set it
        self.man.setPos(self.man,self.walk*globalClock.getDt())
        self.man.setPos(self.man,self.strife*globalClock.getDt())
       
        highestZ = -100
        for i in range(self.manGroundHandler.getNumEntries()):
            entry = self.manGroundHandler.getEntry(i)
            if entry.getIntoNode().getName() == "Cube":
                z = entry.getSurfacePoint(render).getZ()
                if z > highestZ:
                    highestZ = z
        # graity
        self.man.setZ(self.man.getZ()+self.jump*globalClock.getDt())
        self.jump -= 1*globalClock.getDt()
       
        if highestZ > self.man.getZ()-.3:
            self.jump = 0
            self.man.setZ(highestZ+.3)
       
        return task.cont
FPS()
render.setShaderAuto()
run()

Last edited by treeform on Sat May 17, 2008 3:08 pm, edited 2 times in total.
User avatar
treeform
 
Posts: 2106
Joined: Sat May 05, 2007 5:15 pm
Location: SF, CA

Postby rdb » Wed Apr 09, 2008 1:36 am

Looks good. Maybe this could be included in the samples, if we could get a better texture for the walls.
A few suggestions:
* There's no jumping limiter. I can fly!
* Add escape key press to quit. Kinda annoying if you can't quit.
rdb
 
Posts: 11214
Joined: Mon Dec 04, 2006 5:58 am
Location: Netherlands

Postby Hypnos » Wed Apr 09, 2008 3:32 am

I dont know if using __setattr__ is such a good idea for a example.
I mean it's good to learn any new command for a newbie, but this might be a bit off-the panda3d topic.
Just would like to hear other opinions on this.
Hypnos
 
Posts: 585
Joined: Sat Sep 11, 2004 8:07 am
Location: Zürich, Switzerland

Postby treeform » Wed Apr 09, 2008 10:42 am

yeah me too. I like using __setattr__ its makes the code much shorter and its clear what it does but i don't know if its to much of python magic
User avatar
treeform
 
Posts: 2106
Joined: Sat May 05, 2007 5:15 pm
Location: SF, CA

Postby ynjh_jo » Wed Apr 09, 2008 11:34 am

It's messy. It can be a lot simpler, since it is .............. Panda3D ! :D
Code: Select all
import direct.directbase.DirectStart
from direct.showbase.DirectObject import DirectObject
from pandac.PandaModules import *
from direct.interval.IntervalGlobal import LerpFunc
import sys

class FPS(object,DirectObject):
    def __init__(self):
        self.winXhalf = base.win.getXSize()/2
        self.winYhalf = base.win.getYSize()/2
        self.initCollision()
        self.loadLevel()
        self.initPlayer()

    def initCollision(self):
        #initialize traverser
        base.cTrav = CollisionTraverser()
        base.cTrav.setRespectPrevTransform(True)
#         base.cTrav.showCollisions(render)
        #initialize pusher
        self.pusher = CollisionHandlerPusher()
        # collision bits
        self.groundCollBit = BitMask32.bit(0)
        self.collBitOff = BitMask32.allOff()

    def loadLevel(self):

        #load level
        # must have
        #<Group> *something* {
        #  <Collide> { Polyset keep descend } in the egg file
        level = loader.loadModel('level.egg')
        level.reparentTo(render)
        level.setPos(0,0,0)
        level.setColor(1,1,1,.5)

    def initPlayer(self):
        #load man
        self.man = render.attachNewNode('man') # keep this node scaled to identity
        self.man.setPos(0,0,0)
        # should be avatar model
#         model = loader.loadModel('teapot')
#         model.reparentTo(self.man)
#         model.setScale(.05)
        # camera
        base.camera.reparentTo(self.man)
        base.camera.setPos(0,0,1.7)
        base.camLens.setNearFar(.1,1000)
        base.disableMouse()
        #create a collsion solid around the man
        manC = self.man.attachCollisionSphere('manSphere', 0,0,1, .4, self.groundCollBit,self.collBitOff)
        self.pusher.addCollider(manC,self.man)
        base.cTrav.addCollider(manC,self.pusher)

        speed = 4
        Forward = Vec3(0,speed*2,0)
        Back = Vec3(0,-speed,0)
        Left = Vec3(-speed,0,0)
        Right = Vec3(speed,0,0)
        Stop = Vec3(0)
        self.walk = Stop
        self.strife = Stop
        self.jump = 0
        taskMgr.add(self.move, 'move-task')
        self.jumping = LerpFunc( Functor(self.__setattr__,"jump"),
                                 duration=.25, fromData=.25, toData=0)
        self.accept( "escape",sys.exit )
        self.accept( "space" , self.startJump)
        self.accept( "s" , self.__setattr__,["walk",Back] )
        self.accept( "w" , self.__setattr__,["walk",Forward])
        self.accept( "s-up" , self.__setattr__,["walk",Stop] )
        self.accept( "w-up" , self.__setattr__,["walk",Stop] )
        self.accept( "a" , self.__setattr__,["strife",Left])
        self.accept( "d" , self.__setattr__,["strife",Right] )
        self.accept( "a-up" , self.__setattr__,["strife",Stop] )
        self.accept( "d-up" , self.__setattr__,["strife",Stop] )

        self.manGroundColNp = self.man.attachCollisionRay( 'manRay',
                                                           0,0,.6, 0,0,-1,
                                                           self.groundCollBit,self.collBitOff)
        self.manGroundHandler = CollisionHandlerGravity()
        self.manGroundHandler.addCollider(self.manGroundColNp,self.man)
        base.cTrav.addCollider(self.manGroundColNp, self.manGroundHandler)

    def startJump(self):
        if self.manGroundHandler.isOnGround():
           self.jumping.start()

    def move(self,task):
        dt=globalClock.getDt()
        # mouse
        md = base.win.getPointer(0)
        x = md.getX()
        y = md.getY()
        if base.win.movePointer(0, self.winXhalf, self.winYhalf):
            self.man.setH(self.man, (x - self.winXhalf)*-0.1)
            base.camera.setP( clampScalar(-90,90, base.camera.getP() - (y - self.winYhalf)*0.1) )
        # move where the keys set it
        moveVec=(self.walk+self.strife)*dt # horisontal
        moveVec.setZ( self.jump )          # vertical
        self.man.setFluidPos(self.man,moveVec)
        # jump damping
        if self.jump>0:
           self.jump = clampScalar( 0,1, self.jump*.9 )

        return task.cont
FPS()
render.setShaderAuto()
run()
http://jon1.us
Intel Core i7-4500U | AMD Radeon M230 2GB
User avatar
ynjh_jo
 
Posts: 1795
Joined: Tue Apr 18, 2006 12:41 am
Location: Malang, Indonesia

Postby rdb » Wed Apr 09, 2008 12:27 pm

jnjh, you are inheriting from DirectObject, why would you?
Last edited by rdb on Thu Apr 10, 2008 2:04 am, edited 1 time in total.
rdb
 
Posts: 11214
Joined: Mon Dec 04, 2006 5:58 am
Location: Netherlands

Postby treeform » Wed Apr 09, 2008 2:57 pm

ill update with my new script when i get home. I think ynjh_jo made the sliding/jump correct without the down facing ray that would be awsome! Ill check the code tonight and integrate it to the FPS game if it works.
User avatar
treeform
 
Posts: 2106
Joined: Sat May 05, 2007 5:15 pm
Location: SF, CA

Postby Shaba1 » Wed Apr 09, 2008 6:46 pm

One thing you forgot treeform. Is a way to EXIT the script. I kept hitting ESC and Q key finally I had to do a CTRL_ALT_DEL to get out of it.
Shaba1
 
Posts: 196
Joined: Sat Sep 24, 2005 1:26 pm

Postby Crimity » Wed Apr 09, 2008 6:59 pm

Thanks Treeform.. this is going to be really useful for me and a lot of people out there I'm sure.. I hope that this or something similar will be in the samples dir in a future release.

The default fov makes it a bit wacky though.. I changed mine to 70 (hl2's default I think).. easier to understand what's going on.
User avatar
Crimity
 
Posts: 21
Joined: Sun Mar 19, 2006 6:50 am

Postby treeform » Wed Apr 09, 2008 7:05 pm

yes Crimity fov also bothered me ill change it. I would also want to get crates, doors and some monsters in. I also want to keep the script as small and as intuitive as possible good thing python makes this easy. Stay tuned for next iteration.
User avatar
treeform
 
Posts: 2106
Joined: Sat May 05, 2007 5:15 pm
Location: SF, CA

Postby ynjh_jo » Thu Apr 10, 2008 4:22 am

jnjh, you are inheriting from DirectObject, why would you?

It's not me, it's Treeform. What's the problem anyway ? The scene is too simple, so I think it's OK to leave it that way.

I think ynjh_jo made the sliding/jump correct without the down facing ray that would be awsome!

No, that ray is still around, but I use the simpler construction method in libpandamodules.py, since it's 1 collision node with 1 solid only.
Treeform, why don't you fix the reversed normals by hands ? Simply using 2-sided render mode doesn't solve it entirely. CHPusher uses the normal to determine where to push, so if you're colliding to the reversed wall, you'd sucked out of the room.
http://jon1.us
Intel Core i7-4500U | AMD Radeon M230 2GB
User avatar
ynjh_jo
 
Posts: 1795
Joined: Tue Apr 18, 2006 12:41 am
Location: Malang, Indonesia

Postby treeform » Thu Apr 10, 2008 1:21 pm

yes i fixed lots of the bugs and cleaned up the code ill use your ray system and post a new sample when i finally have some time!
User avatar
treeform
 
Posts: 2106
Joined: Sat May 05, 2007 5:15 pm
Location: SF, CA

Postby treeform » Wed Apr 30, 2008 12:56 am

i have added a new sample take a look if you like
http://istrolid.com/p/panda3d/simple-fps.zip
User avatar
treeform
 
Posts: 2106
Joined: Sat May 05, 2007 5:15 pm
Location: SF, CA

Postby newfych » Thu May 01, 2008 9:27 am

Hi, treeform! I think there are some problems in your code:
Still unable to exit with escape key
When i comment render.setShaderAuto() with # it has no effect
Jumping is very slow and not real (some kind of character's center jumping, not the legs)
There is a mouse cursor visible during the game
No limits to move camera up and down
It's possible to see teapot cover under the player itself ;)

PS. IMHO ynjh_jo has made jump process better.
Good luck!
User avatar
newfych
 
Posts: 16
Joined: Sat Mar 15, 2008 10:11 am
Location: Russia

Postby Traker » Thu May 01, 2008 9:00 pm

To remove the mouse just add the lines below this line :

""" create a FPS type game """

props = WindowProperties()
props.setCursorHidden(True)
base.win.requestProperties(props)

escape key works on my comp

not bad for a simple fps script...should definetly be improved ;)
Traker
 
Posts: 3
Joined: Thu May 01, 2008 8:55 pm

Postby Zothen » Thu May 15, 2008 9:32 am

I noticed some odd strafing behaviour. When I change the strafing direction very fast (left <-> right) it seems that the strafing movement gets locked and I dont strafe to the direction I press the key. Anybody else noticing this? Hope its not my keyboard, hehe!
Zothen
 
Posts: 30
Joined: Tue Feb 27, 2007 8:12 pm
Location: Tanelorn

Postby ynjh_jo » Thu May 15, 2008 11:26 am

Yes, that's what he missed. Treeform uses a simple event-driven movement direction assignment.
Code: Select all
self.accept( "a" , self.__setattr__,["strife",Left])
self.accept( "d" , self.__setattr__,["strife",Right] )
self.accept( "a-up" , self.__setattr__,["strife",Stop] )
self.accept( "d-up" , self.__setattr__,["strife",Stop] )

It means, each "-up" event simply assigns zero movement vector, regardless of the first key down-state. So, you'd see this "feature" if you hold down A and D (or W and S) in sequence (not necessarily fast), then release one of them, and you'd stay still, since the key-release simply sets the movement vector to zero.

I guess he must intended to cut down the development time by using a simple vector assignment, rather than recording key-down states.
http://jon1.us
Intel Core i7-4500U | AMD Radeon M230 2GB
User avatar
ynjh_jo
 
Posts: 1795
Joined: Tue Apr 18, 2006 12:41 am
Location: Malang, Indonesia

Postby rdb » Sun May 25, 2008 6:23 am

How about including this example in the sample programs?
rdb
 
Posts: 11214
Joined: Mon Dec 04, 2006 5:58 am
Location: Netherlands

Postby dorosp » Sat May 31, 2008 1:15 pm

kind of a noob question...

I am trying to use the script to control my own model, here is the code :

Code: Select all
class FPS(object,DirectObject):

    def __init__(self):
       
        self.initCollision()
        self.loadLevel()
        self.initPlayer()
        self.camera()
       
   
    def initCollision(self):
        #initialize traverser
        base.cTrav = CollisionTraverser()
        base.cTrav.setRespectPrevTransform(True)
#         base.cTrav.showCollisions(render)
        #initialize pusher
        self.pusher = CollisionHandlerPusher()
        # collision bits
        self.groundCollBit = BitMask32.bit(0)
        self.collBitOff = BitMask32.allOff()

   
    def loadLevel(self):

        level = loader.loadModel('mine/road.egg')
        level.reparentTo(render)
        level.setPos(-10,-10,-6)
        level.setColor(1,1,1,.5)
        level.setScale(10)
   
    def initPlayer(self) :
        self.man = Actor("mine/toxotis",
                                 {"run":"mine/toxotis_run",
                                  "walk":"mine/toxotis_idle"})
        self.man.reparentTo(render)
        self.man.setScale(1)
        #self.man.setPos(0,0,-0.02)

        #create a collsion solid around the man
        manC = self.man.attachCollisionSphere('manSphere', 0,0,1, .4, self.groundCollBit,self.collBitOff)
        self.pusher.addCollider(manC,self.man)
        base.cTrav.addCollider(manC,self.pusher)

        speed = 6
        Forward = Vec3(0,-speed*2,0)
        Back = Vec3(0,speed,0)
        Left = Vec3(-speed,0,0)
        Right = Vec3(speed,0,0)
        Stop = Vec3(0)
        self.walk = Stop
        self.strife = Stop
        self.jump = 0
        taskMgr.add(self.move, 'move-task')
        self.jumping = LerpFunc( Functor(self.__setattr__,"jump"),
                                 duration=.25, fromData=.25, toData=0)
        self.accept( "escape",sys.exit )
        self.accept( "space" , self.startJump)
        self.accept( "s" , self.__setattr__,["walk",Back] )
        self.accept( "w" , self.__setattr__,["walk",Forward])
        self.accept( "s-up" , self.__setattr__,["walk",Stop] )
        self.accept( "w-up" , self.__setattr__,["walk",Stop] )
        self.accept( "a" , self.__setattr__,["strife",Left])
        self.accept( "d" , self.__setattr__,["strife",Right] )
        self.accept( "a-up" , self.__setattr__,["strife",Stop] )
        self.accept( "d-up" , self.__setattr__,["strife",Stop] )

        self.manGroundColNp = self.man.attachCollisionRay( 'manRay',
                                                           0,0,.6, 0,0,-1,
                                                           self.groundCollBit,self.collBitOff)
        self.manGroundHandler = CollisionHandlerGravity()
        self.manGroundHandler.addCollider(self.manGroundColNp,self.man)
        base.cTrav.addCollider(self.manGroundColNp, self.manGroundHandler)
       
           
           

    def startJump(self):
        if self.manGroundHandler.isOnGround():
           self.jumping.start()

    def move(self,task):
        dt=globalClock.getDt()
        # mouse
        md = base.win.getPointer(0)
        x = md.getX()
        y = md.getY()
       
        # move where the keys set it
        moveVec=(self.walk+self.strife)*dt # horisontal
        moveVec.setZ( self.jump )          # vertical
        self.man.setFluidPos(self.man,moveVec)
        # jump damping
        if self.jump>0:
           self.jump = clampScalar( 0,1, self.jump*.9 )
       
        # If man is moving, loop the run animation.
        # If he is standing still, stop the animation.
       
        if self.walk == Forward:
            self.man.loop("run")
                       
        return task.cont
   
    def camera(self) :
   
        # Create a floater object.  We use the "floater" as a temporary
        # variable in a variety of calculations.
       
        #self.floater = NodePath(PandaNode("floater"))
        #self.floater.reparentTo(render)

        # Set up the camera
       
        #base.disableMouse()
        #base.camera.setPos(-100,-20,20)
        #base.camera.setPos(self.man.getX(),self.man.getY()+10,2)
       
       
       

        # If the camera is too far from ralph, move it closer.
        # If the camera is too close to ralph, move it farther.

        camvec = self.man.getPos() - base.camera.getPos()
        camvec.setZ(0)
        camdist = camvec.length()
        camvec.normalize()
        if (camdist > 10.0):
            base.camera.setPos(base.camera.getPos() + camvec*(camdist-10))
            camdist = 10.0
        if (camdist < 5.0):
            base.camera.setPos(base.camera.getPos() - camvec*(5-camdist))
            camdist = 5.0

               
        # The camera should look in ralph's direction,
        # but it should also try to stay horizontal, so look at
        # a floater which hovers above ralph's head.
       
        #self.floater.setPos(self.man.getPos())
        #self.floater.setZ(self.man.getZ() + 2.0)
        base.camera.lookAt(self.man)

       
        return Task.cont


FPS()
render.setShaderAuto()
run()



I now try to loop the animation of the model and I go to the move function, and I say :

Code: Select all

if self.walk == Forward:
   self.man.loop("run")



An error is produced because Forward is not a global variable. I realize that is only declared in the function initplayer. How can i declare it glabally?

thanx!
Na sas fai i moula!
dorosp
 
Posts: 47
Joined: Tue Nov 20, 2007 3:06 pm

Postby treeform » Sat May 31, 2008 4:36 pm

Forward is just Vec3(0,1,0) nothing magical

You can move the definitions into the top of the file.
User avatar
treeform
 
Posts: 2106
Joined: Sat May 05, 2007 5:15 pm
Location: SF, CA

Postby xaddict » Sun Sep 07, 2008 6:35 am

How would one make the jumping faster? it seems like a low gravity example... what would I have to do to increase the speed with which the character jumps/falls?

it would be cool if that would also be a variable where the other variables are declared
xaddict
 
Posts: 14
Joined: Thu Sep 04, 2008 10:28 am

Postby xaddict » Sun Sep 07, 2008 8:36 am

I made my own level with 3ds max and exported it with the 3ds max egg exporter with the material given in the test sample zip. But there's a problem... my camera keeps falling through the environment.. I'm using single sided polygons and everything is in editable meshes (not polygons). Is there something I should tweak to make this work?
xaddict
 
Posts: 14
Joined: Thu Sep 04, 2008 10:28 am

Postby ThomasEgi » Sun Sep 07, 2008 8:59 am

there is a comment in the function for loading the level:
Code: Select all
        # must have
        #<Group> *something* {
        #  <Collide> { Polyset keep descend } in the egg file

add it to your egg file and it should work
User avatar
ThomasEgi
 
Posts: 2163
Joined: Fri Jul 28, 2006 10:43 am
Location: Germany,Koblenz

Postby xaddict » Sun Sep 07, 2008 9:54 am

ThomasEgi wrote:there is a comment in the function for loading the level:
Code: Select all
        # must have
        #<Group> *something* {
        #  <Collide> { Polyset keep descend } in the egg file

add it to your egg file and it should work


I exported a simple box object from 3ds max. it's a editable mesh. I added the <collision> part but it still doesn't work..

here's the insides of plane.egg:

Code: Select all
<CoordinateSystem> { Z-Up }

<Comment> {
  "MaxEggPlugin nul.max -a model -bface 'C:\Panda3D-1.5.2\samples\simple-fps\plane.egg'"
}
<Group> {
  <Dart> { 1 }
  <Group> Box01 {
  <Collide> { Polyset keep descend }
    <VertexPool> Box01.verts {
      <Vertex> 0 {
        -100 -100 0
        <UV> { 1 0 }
        <Normal> { 0 0 -1 }
      }
      <Vertex> 1 {
        -100 100 0
        <UV> { 1 1 }
        <Normal> { 0 0 -1 }
      }
      <Vertex> 2 {
        100 100 0
        <UV> { 0 1 }
        <Normal> { 0 0 -1 }
      }
      <Vertex> 3 {
        100 -100 0
        <UV> { 0 0 }
        <Normal> { 0 0 -1 }
      }
      <Vertex> 4 {
        -100 -100 30
        <UV> { 0 0 }
        <Normal> { 0 0 1 }
      }
      <Vertex> 5 {
        100 -100 30
        <UV> { 1 0 }
        <Normal> { 0 0 1 }
      }
      <Vertex> 6 {
        100 100 30
        <UV> { 1 1 }
        <Normal> { 0 0 1 }
      }
      <Vertex> 7 {
        -100 100 30
        <UV> { 0 1 }
        <Normal> { 0 0 1 }
      }
      <Vertex> 8 {
        -100 -100 0
        <UV> { 0 0 }
        <Normal> { 0 -1 0 }
      }
      <Vertex> 9 {
        100 -100 0
        <UV> { 1 0 }
        <Normal> { 0 -1 0 }
      }
      <Vertex> 10 {
        100 -100 30
        <UV> { 1 1 }
        <Normal> { 0 -1 0 }
      }
      <Vertex> 11 {
        -100 -100 30
        <UV> { 0 1 }
        <Normal> { 0 -1 0 }
      }
      <Vertex> 12 {
        100 -100 0
        <UV> { 0 0 }
        <Normal> { 1 0 0 }
      }
      <Vertex> 13 {
        100 100 0
        <UV> { 1 0 }
        <Normal> { 1 0 0 }
      }
      <Vertex> 14 {
        100 100 30
        <UV> { 1 1 }
        <Normal> { 1 0 0 }
      }
      <Vertex> 15 {
        100 -100 30
        <UV> { 0 1 }
        <Normal> { 1 0 0 }
      }
      <Vertex> 16 {
        100 100 0
        <UV> { 0 0 }
        <Normal> { 0 1 0 }
      }
      <Vertex> 17 {
        -100 100 0
        <UV> { 1 0 }
        <Normal> { 0 1 0 }
      }
      <Vertex> 18 {
        -100 100 30
        <UV> { 1 1 }
        <Normal> { 0 1 0 }
      }
      <Vertex> 19 {
        100 100 30
        <UV> { 0 1 }
        <Normal> { 0 1 0 }
      }
      <Vertex> 20 {
        -100 100 0
        <UV> { 0 0 }
        <Normal> { -1 0 0 }
      }
      <Vertex> 21 {
        -100 -100 0
        <UV> { 1 0 }
        <Normal> { -1 0 0 }
      }
      <Vertex> 22 {
        -100 -100 30
        <UV> { 1 1 }
        <Normal> { -1 0 0 }
      }
      <Vertex> 23 {
        -100 100 30
        <UV> { 0 1 }
        <Normal> { -1 0 0 }
      }
    }
    <Polygon> {
      <RGBA> { 0.588235 0.588235 0.588235 1 }
      <BFace> { 1 }
      <VertexRef> { 0 1 2 <Ref> { Box01.verts } }
    }
    <Polygon> {
      <RGBA> { 0.588235 0.588235 0.588235 1 }
      <BFace> { 1 }
      <VertexRef> { 2 3 0 <Ref> { Box01.verts } }
    }
    <Polygon> {
      <RGBA> { 0.588235 0.588235 0.588235 1 }
      <BFace> { 1 }
      <VertexRef> { 4 5 6 <Ref> { Box01.verts } }
    }
    <Polygon> {
      <RGBA> { 0.588235 0.588235 0.588235 1 }
      <BFace> { 1 }
      <VertexRef> { 6 7 4 <Ref> { Box01.verts } }
    }
    <Polygon> {
      <RGBA> { 0.588235 0.588235 0.588235 1 }
      <BFace> { 1 }
      <VertexRef> { 8 9 10 <Ref> { Box01.verts } }
    }
    <Polygon> {
      <RGBA> { 0.588235 0.588235 0.588235 1 }
      <BFace> { 1 }
      <VertexRef> { 10 11 8 <Ref> { Box01.verts } }
    }
    <Polygon> {
      <RGBA> { 0.588235 0.588235 0.588235 1 }
      <BFace> { 1 }
      <VertexRef> { 12 13 14 <Ref> { Box01.verts } }
    }
    <Polygon> {
      <RGBA> { 0.588235 0.588235 0.588235 1 }
      <BFace> { 1 }
      <VertexRef> { 14 15 12 <Ref> { Box01.verts } }
    }
    <Polygon> {
      <RGBA> { 0.588235 0.588235 0.588235 1 }
      <BFace> { 1 }
      <VertexRef> { 16 17 18 <Ref> { Box01.verts } }
    }
    <Polygon> {
      <RGBA> { 0.588235 0.588235 0.588235 1 }
      <BFace> { 1 }
      <VertexRef> { 18 19 16 <Ref> { Box01.verts } }
    }
    <Polygon> {
      <RGBA> { 0.588235 0.588235 0.588235 1 }
      <BFace> { 1 }
      <VertexRef> { 20 21 22 <Ref> { Box01.verts } }
    }
    <Polygon> {
      <RGBA> { 0.588235 0.588235 0.588235 1 }
      <BFace> { 1 }
      <VertexRef> { 22 23 20 <Ref> { Box01.verts } }
    }
  }
}
xaddict
 
Posts: 14
Joined: Thu Sep 04, 2008 10:28 am

Postby ynjh_jo » Sun Sep 07, 2008 11:34 am

Either export it as static mesh, or remove the <Dart> tag in the egg.
http://jon1.us
Intel Core i7-4500U | AMD Radeon M230 2GB
User avatar
ynjh_jo
 
Posts: 1795
Joined: Tue Apr 18, 2006 12:41 am
Location: Malang, Indonesia

Postby xaddict » Sun Sep 07, 2008 2:24 pm

ynjh_jo wrote:Either export it as static mesh, or remove the <Dart> tag in the egg.


I removed the Dart tag from the .egg file and nothing happened... how do I export a static mesh from 3ds max? it only has editable mesh and editable poly
xaddict
 
Posts: 14
Joined: Thu Sep 04, 2008 10:28 am

Postby ynjh_jo » Sun Sep 07, 2008 2:46 pm

There used to be "pose" option, I don't know about the new exporter.
http://jon1.us
Intel Core i7-4500U | AMD Radeon M230 2GB
User avatar
ynjh_jo
 
Posts: 1795
Joined: Tue Apr 18, 2006 12:41 am
Location: Malang, Indonesia

Postby xaddict » Sun Sep 07, 2008 2:59 pm

ynjh_jo wrote:There used to be "pose" option, I don't know about the new exporter.


I don't know if there is a 'new' exporter, since the one for max is pretty old...

I changed the type to pose and exported with double-sided polygons and somehow if I export a box (editable mesh) made with the most basic tools the program doesn't find the collision.

here's my code:

Code: Select all
<CoordinateSystem> { Z-Up }
<Texture> Tex1 {
  6061.jpg
  <Scalar> format { rgb }
  <Scalar> wrapu { repeat }
  <Scalar> wrapv { repeat }
  <Scalar> minfilter { linear_mipmap_linear }
  <Scalar> magfilter { linear }
}
<Group> Plane01 {
   <Collide> { Polyset keep descend }
  <Transform> {
    <Matrix4> {
      -1 -1.50996e-007 0 0
      1.50996e-007 -1 0 0
      0 0 1 0
      -5 -5 0 1
    }
  }
  <VertexPool> Plane01.verts {
    <Vertex> 0 {
      10.25 -20 1.35307
      <UV> { 0 1 }
      <Normal> { 0 0 1 }
    }
    <Vertex> 1 {
      10.25 10 1.35307
      <UV> { 0 0 }
      <Normal> { 0 0 1 }
    }
    <Vertex> 2 {
      -19.75 -20 1.35307
      <UV> { 1 1 }
      <Normal> { 0 0 1 }
    }
    <Vertex> 3 {
      -19.75 10 1.35307
      <UV> { 1 0 }
      <Normal> { 0 0 1 }
    }
    <Vertex> 4 {
      10 -20 0
      <UV> { 0 1 }
      <Normal> { 0.983361 1.48483e-007 -0.181662 }
    }
    <Vertex> 5 {
      10 10 0
      <UV> { 0 0 }
      <Normal> { 0.983361 1.48483e-007 -0.181662 }
    }
    <Vertex> 6 {
      10.25 10 1.35307
      <UV> { 0 0 }
      <Normal> { 0.983361 1.48483e-007 -0.181662 }
    }
    <Vertex> 7 {
      10.25 -20 1.35307
      <UV> { 0 1 }
      <Normal> { 0.983361 1.48483e-007 -0.181662 }
    }
    <Vertex> 8 {
      -20 -20 0
      <UV> { 1 1 }
      <Normal> { 1.50996e-007 -1 0 }
    }
    <Vertex> 9 {
      10 -20 0
      <UV> { 0 1 }
      <Normal> { 1.50996e-007 -1 0 }
    }
    <Vertex> 10 {
      10.25 -20 1.35307
      <UV> { 0 1 }
      <Normal> { 1.50996e-007 -1 0 }
    }
    <Vertex> 11 {
      -19.75 -20 1.35307
      <UV> { 1 1 }
      <Normal> { 1.19207e-007 -1 7.10698e-007 }
    }
    <Vertex> 12 {
      -20 10 0
      <UV> { 1 0 }
      <Normal> { -0.983361 -1.48483e-007 0.181662 }
    }
    <Vertex> 13 {
      -20 -20 0
      <UV> { 1 1 }
      <Normal> { -0.983361 -1.48483e-007 0.181662 }
    }
    <Vertex> 14 {
      -19.75 -20 1.35307
      <UV> { 1 1 }
      <Normal> { -0.983361 -1.48483e-007 0.181662 }
    }
    <Vertex> 15 {
      -19.75 10 1.35307
      <UV> { 1 0 }
      <Normal> { -0.983361 -1.48483e-007 0.181662 }
    }
    <Vertex> 16 {
      10 10 0
      <UV> { 0 0 }
      <Normal> { -1.50996e-007 1 -7.04825e-007 }
    }
    <Vertex> 17 {
      -20 10 0
      <UV> { 1 0 }
      <Normal> { -1.50996e-007 1 -7.04825e-007 }
    }
    <Vertex> 18 {
      -19.75 10 1.35307
      <UV> { 1 0 }
      <Normal> { -1.50996e-007 1 -7.04825e-007 }
    }
    <Vertex> 19 {
      10.25 10 1.35307
      <UV> { 0 0 }
      <Normal> { -1.19207e-007 1 -5.87258e-009 }
    }
  }
  <Polygon> {
    <RGBA> { 1 1 1 1 }
    <TRef> { Tex1 }
    <BFace> { 1 }
    <VertexRef> { 0 1 2 <Ref> { Plane01.verts } }
  }
  <Polygon> {
    <RGBA> { 1 1 1 1 }
    <TRef> { Tex1 }
    <BFace> { 1 }
    <VertexRef> { 3 2 1 <Ref> { Plane01.verts } }
  }
  <Polygon> {
    <RGBA> { 1 1 1 1 }
    <TRef> { Tex1 }
    <BFace> { 1 }
    <VertexRef> { 4 5 6 <Ref> { Plane01.verts } }
  }
  <Polygon> {
    <RGBA> { 1 1 1 1 }
    <TRef> { Tex1 }
    <BFace> { 1 }
    <VertexRef> { 6 7 4 <Ref> { Plane01.verts } }
  }
  <Polygon> {
    <RGBA> { 1 1 1 1 }
    <TRef> { Tex1 }
    <BFace> { 1 }
    <VertexRef> { 8 9 10 <Ref> { Plane01.verts } }
  }
  <Polygon> {
    <RGBA> { 1 1 1 1 }
    <TRef> { Tex1 }
    <BFace> { 1 }
    <VertexRef> { 10 11 8 <Ref> { Plane01.verts } }
  }
  <Polygon> {
    <RGBA> { 1 1 1 1 }
    <TRef> { Tex1 }
    <BFace> { 1 }
    <VertexRef> { 12 13 14 <Ref> { Plane01.verts } }
  }
  <Polygon> {
    <RGBA> { 1 1 1 1 }
    <TRef> { Tex1 }
    <BFace> { 1 }
    <VertexRef> { 14 15 12 <Ref> { Plane01.verts } }
  }
  <Polygon> {
    <RGBA> { 1 1 1 1 }
    <TRef> { Tex1 }
    <BFace> { 1 }
    <VertexRef> { 16 17 18 <Ref> { Plane01.verts } }
  }
  <Polygon> {
    <RGBA> { 1 1 1 1 }
    <TRef> { Tex1 }
    <BFace> { 1 }
    <VertexRef> { 18 19 16 <Ref> { Plane01.verts } }
  }
}
xaddict
 
Posts: 14
Joined: Thu Sep 04, 2008 10:28 am

Postby ynjh_jo » Sun Sep 07, 2008 3:22 pm

Try to name the <collide> with the <group> name.
http://jon1.us
Intel Core i7-4500U | AMD Radeon M230 2GB
User avatar
ynjh_jo
 
Posts: 1795
Joined: Tue Apr 18, 2006 12:41 am
Location: Malang, Indonesia

Postby treeform » Sun Sep 07, 2008 5:51 pm

on a side note i recommend running all collision meshes it through my collisions optimizer:

http://panda3d.org/phpbb2/viewtopic.php?p=23267#23267

I have seen speed ups of x10 times and more!
User avatar
treeform
 
Posts: 2106
Joined: Sat May 05, 2007 5:15 pm
Location: SF, CA

Next

Return to Code Snippets

Who is online

Users browsing this forum: No registered users and 3 guests