Collisions?

Im a bit confused with collisions…
I tried to make a terrain and player collision by reading the Roaming Ralph sample. With my own model and the default terrain it works, with my own terrain it doesnt. Im guessing the default world.egg file has some kind of a lowpoly version of it for collisions. Is that the case?

As far as I remember Roaming Ralphs collisions is just a simple ray that checks the ground textures name, so if the ray does not hit the ground texture no movement is allowed.
Sry, but cant point you to the right code part from this computer here, but check the ray and you will find it.

Yes it checks each section to see if it’s named. In my case it’s named “terrain” so any objects or faces named terrain become a solid ground to Ralph.

If you look at the python code you will find a section that shows this.

JB SKaggs

On the egg file of the terrain in RR the ground geometry has a collide tag: { Polyset keep descend }. That tells panda to make a invisible copy of the terrain and add it to the collision traverser as an into object.

In theory it should be a low-poly version but in RR the terrain has 2k polys ^^

The best way is to make the collision geometry with the octree script: discourse.panda3d.org/viewtopic … &highlight

the chicken exporter doesnt seem to have an option like that.
I added it manually an it worked.
I still need to understand some part of the code though

I’ve a friend who gave up of using panda3d because collisions, I didn’t give up yet, I am waiting some day understand Panda3D’s Collision System, it’s very hard to use I think, I am looking Unity3D maybe it would be easier there, but even so I am sad because I love python and I would like to keep using an engine that fully supports python. :cry:

collisions is simply checking coordinates between objects.

It seems complicated because it is basically geometry applied- which seems complicated until you understand it.

the naming of tags- such as collide, terrain, or ground etc is simply a variable of an arbritary tag set to identify a spot in the 3d scene. Tags are generally set to create a group of objects- so if an object has a tag collide then you can setup your code to not allow pass through the object.

but I could call my tag “stop”, or “solid” or whatever I want as long as my code looks for that tag.

I have had problems getting blnder to set tags properly (my ignorance not blender’s) so I just set them in the egg file. But most of the time I just as easily use the object’s name. The problem I face is laziness- I don’t want to restudy geometry or study somelse’s code deeply so I get frustrated and quit.

But after a while studying this it makes more sense to me- remember python and panda are languages and it takes time to pick up a new language.

http://www.youtube.com/watch?v=dw5DxESx_1Q
in case you feel like using tags in blender :slight_smile:

How many tags can a objects have? How do tags differ from names? and groups?

Hi,
I am new to panda, and at the moment I am learning the collision-part of the manual.

If I understand it good, your models (like from 3d studio max) are just an visual illusion, and to make them interactive, you have to use collisions?

Well yes. Even you physically use collisions- your senses measure the distance to another object and tell you if it touching you or not, how close, how warm, how smelly etc.

In programming the collision is similar to the type of senses the object has. So it is a matter of telling the computer how to sense the interactions of objects.

JB

hi again,

I tried some things with that collison stuf, the program runs fine, but I never get the message (in cmd) ‘entry’, can sombody help?

import direct.directbase.DirectStart
from pandac.PandaModules import *
from direct.showbase import DirectObject
from direct.task import Task
from direct.actor import Actor
from direct.interval.IntervalGlobal import *
from direct.gui.OnscreenText import OnscreenText
from direct.task.Task import Task
import math

#Load the first environment model
m = loader.loadModel("models/teapot")
m.reparentTo(render)
m.setScale(0.25,0.25,0.25)
m.setPos(-8,42,5)
m.setH(m,-90)

#Load the first environment model
s = loader.loadModel("models/teapot")
s.reparentTo(render)
s.setScale(0.5,0.5,0.5)
s.setPos(0,42,5)

#
segment = CollisionSegment(0, 0, 0, 0, 10, 0)

cnodePath5 = m.attachNewNode(CollisionNode('cnode5'))
cnodePath5.node().addSolid(segment)

cnodePath5.show()

#
sphere = CollisionSphere(0, 0, 0, 4)

cnodePath = s.attachNewNode(CollisionNode('cnode1'))
cnodePath.node().addSolid(sphere)

cnodePath.show()

class MyObject(DirectObject.DirectObject):
    def __init__(self):
        self.accept('cnode5-into-cnode1', self.handleRailCollision)
        
    def handleRailCollision(self, entry):
        print 'entry'

def myFunction(task):
    m.setPos(m,0,1,0)
    return task.again

taskMgr.add(myFunction, 'MyTaskName')

h = MyObject()

run()

i dont really get how eactly you want to use the collision system here. but i dont see a collision traverser. which you usualy need. therefore there is no traverse() call which you need too. i guess…
you also seems to move your object quite fast but i dont think that matters if you’r looking for the collision event only.

hi, tanx for your reply.
I updated my code, but I didnt test it yet :

 import direct.directbase.DirectStart 
from pandac.PandaModules import * 
from direct.showbase import DirectObject 
from direct.task import Task 
from direct.actor import Actor 
from direct.interval.IntervalGlobal import * 
from direct.gui.OnscreenText import OnscreenText 
from direct.task.Task import Task 
import math 

#Load the first environment model 
m = loader.loadModel("models/teapot") 
m.reparentTo(render) 
m.setScale(0.25,0.25,0.25) 
m.setPos(-8,42,5) 
m.setH(m,-90) 

#Load the first environment model 
s = loader.loadModel("models/teapot") 
s.reparentTo(render) 
s.setScale(0.5,0.5,0.5) 
s.setPos(0,42,5) 

# 
segment = CollisionSegment(0, 0, 0, 0, 10, 0) 

cnodePath5 = m.attachNewNode(CollisionNode('cnode5')) 
cnodePath5.node().addSolid(segment) 

cnodePath5.show() 

# 
sphere = CollisionSphere(0, 0, 0, 4) 

cnodePath = s.attachNewNode(CollisionNode('cnode1')) 
cnodePath.node().addSolid(sphere) 

cnodePath.show()

#
#Collision handler:
#

class MyObject(DirectObject.DirectObject): 
    def __init__(self): 
        self.accept('cnode5-into-cnode1', self.handleRailCollision) 
        
    def handleRailCollision(self, entry): 
        print 'entry' 

#
#Movement task:
#

def movementktask(task): 
    m.setPos(m,0,1,0) 
    return task.again 

taskMgr.add(movementktask, 'movement1') 

#
#Collision traverser:
#

traverser = CollisionTraverser('traverser name')
base.cTrav = traverser
traverser.addCollider(cnode5, handleRailcollision)

#
#
h = MyObject() 

run()

But I have another question about collisions:

When I load a blue box (a) and a red box(b) and a green box ©,
I would like to get c move up, when it collides with a, and to move down when it collides with b.

Can somoane help getting this in pyhton? thanx.