View Full Version : Panda3d help! .please
01DT!m3r
19-09-2008, 06:22 AM
Please can someone explain to me how to setup a collision system in Panda3d . I am still currently learning the language . But no matter what i do or tutorial i try i cant get it to stop objects going through each other . I am not using high speed collisions . And i am using setfluidPos . Please can someone maybe give me a commentated source code or even just some help here . Thanks in advance :)
A simple way would be to check the object's width, height and length against its position.
This should work for a general not precise) collision, ie when the two spaces of the objects intersect, although its off the top of my head, and will only work if the origin of your object is in the position x y and z axes, and has its origin in the lower left corner (smallest x and y of the object)
return (obj1x < checkingx && obj1x+obj1width > checkingx) && (obj1y < checkingy && obj1y+obj1length> checkingy) &&(obj1z < checkingz && obj1z+obj1height > checkingz)
Im assuming this part of the manual will help: http://panda3d.etc.cmu.edu/wiki/index.php/Collision_Detection
More specifically this page should help you: Collision_solids (http://panda3d.etc.cmu.edu/wiki/index.php/Collision_Solids)
I think the most appropriate option of those show is the one using a ray, as they dont have squares or cubes, so it becomes easiest (in my mind)
CollisionRay
The ray, line, and segment (below) are special collision solids that are useful only as a "from" object; since these objects have no volume, nothing will collide "into" a ray.
The CollisionRay represents an infinite ray that begins at a specific point, and stretches in one direction to infinity.
It is particularly useful for picking objects from the screen, since you can create a ray that starts at the camera's point of view and extends into the screen, and then determine which objects that ray is intersecting. (In fact, there is a method on CollisionRay called setFromLens() that automatically sets up the ray based on a 2-d onscreen coordinate; this is used by the "picker". See Clicking on 3D Objects.)
The CollisionRay is also useful in conjunction with the CollisionHandlerFloor; see Collision Handlers.
A CollisionRay is created by specifing an origin point, and a direction vector. The direction vector need not be normalized.
ray = CollisionRay(ox, oy, oz, dx, dy, dz)
01DT!m3r
19-09-2008, 02:33 PM
Thanks Edge but I have already used those .I have actually used your previous method in delphi 7 to make pong .But I would like to stick to panda3d's built in collision system. Thanks again but I am actually looking for someone who has built a collision system in panda3d.(Thaumaturge ;) )
Thaumaturge
19-09-2008, 07:57 PM
*appears in a flash of blue fire* You summoned? ;)
First of all, I really recommend that, if you haven't, you post Panda-related problems on the Panda forums - I've found people there to be very helpful, and myself post there.
Secondly, do use the manual (http://panda3d.net/wiki/index.php) - it should, I think, be your first stop, and I've found it to be very informative more often than not (and includes not only information on but also examples of collision detection, as I recall). I'm pretty sure that much, if not all, of what I'm giving below is also given in the manual, in the section on collision detection.
Thirdly, if you don't have particularly fast-moving objects, you can probably get away with not using setFluidPos, although it's also probably not worth removing it now that it's apparently in.
As to your problem, the ray system is probably not what you want, from what you've described, although the pointer to the pages on collision detection and collision solids are indeed the places to look.
In overview, there are a few parts to collision detection:
1) Collision traversers. These run over a scene graph or part of a scene graph looking for collisions; they can be thought of as the "active" parts of the system. Panda projects have a default traverser (base.cTrav, if I recall correctly) that, if instantiated, is automatically run over the scene graph from "render" (and possibly "render2d", I'm not sure, I'm afraid), I believe, although you can create other traversers and run their traversals as suits you, if you wish. For your purposes in this project, it sounds as though you probably want to stick with the default traverser
2) Collision handlers. These register collisions and react in particular ways. As the manual indicates, there are a few types of these; as I recall the most basic is CollisionHandlerEvent, which allows you to register a method to be called when a collision that fits one of the patterns that you register is detected. Perhaps better for you, there is also the CollisionHandlerPusher, which specifically prevents objects from entering each other, and works pretty well for that, as I recall.
3) Collision solids. These are the shapes between which collisions occur. While you can enable collisions with visible geometry, it is, I believe, rather less efficient than using collision geometry, and should probably be avoided unless you have a particularly good reason to make use of it. Take care to read the entries on the various collision solid types, as not all work well as "into" objects, and not all work well as "from" objects, as I recall (see below). Note that you can have custom collision geometry; I believe that that falls under "CollisionPolygon", although if you specify it in a modeller you should have little reason to worry about that.
Note that, for the system to work, you should specify certain collision solids to be "from" objects, or, put another way, "active" objects; collisions are considered to be "from" one object "into" the other. Panda doesn't check everything against everything else, but rather checks a set of "from" objects against all other objects. To specify that an object is to be used as a "from" object, add it and its collision handler to the appropriate collision traverser (again, in your case this will probably just be base.cTrav).
Note too that you can control which objects collide with which other objects using, amongst other techniques, I think, bitmasks, again as detailed in the manual.
01DT!m3r
20-09-2008, 11:37 AM
Thank you thaumaturge ,everything is up and running now , a bit shaky,but running,I have downloaded the parts of the manual for collisions and have started working through them,but you have given me gold here,its just what I needed ,Thank you for your time:)
Thaumaturge
20-09-2008, 09:06 PM
It's my pleasure - I'm glad to hear that you have things up and running. ^_^
Again again, if you haven't already, it's probably a good idea for you to sign up at the Panda forums; you should have more people available to you there who know Panda well - better than I, for that matter, in a number of cases. I've found it to be a very good place at which to ask Panda-related questions.
Good luck with whatever project you're working on. ^_^
01DT!m3r
20-09-2008, 09:17 PM
Thanks , I definitely will sign up there , but before I do I have one little question, I am making a very basic racing game at the moment , but every time the car collides with the wall it goes crazy , I am using a CollisionHandlerPusher() for my collisions , Is there another way I can go ,so that the car just stops when it hits the wall and not get pushed away depending on its angle of interception?Thanks again
Thaumaturge
20-09-2008, 10:31 PM
Hmm - that sounds odd.
What do you mean by "goes crazy"? I may be missing something, but that's not the sort of behaviour that I'd expect from a basic CollisionHandlerPusher implementation - I've had generally good experiences with it.
Perhaps it would also help for you to post your collision setup and handling code for me to take a look at...
I realise that I'm not answering the question that you asked, but I suspect at the moment that this tack might be more beneficial.
01DT!m3r
21-09-2008, 01:12 PM
Sure thing ,Ok the car when it collides ,is pushed back in the opposite direction it was heading and then collides with the next object and does same thing,and repeats until its back quite a distance,here is the sourcehttp://www.mediafire.com/?sharekey=5ed5780884297ce2d2db6fb9a8902bda
Thaumaturge
21-09-2008, 10:15 PM
Hmm... First of all, I think that it would probably help you a lot to take into account in your tasks the time between frames - at the moment the game is running rather too fast on my side for easy testing, without my either building in a workaround or running a CPU-slowdown utility.
At the moment, if I'm not much mistaken, the faster the computer processes the tasks, the more times that the task will be executed, and thus the faster your object will seem to move and turn. In order to rectify this, try taking the time since the last update and multiplying your various movements and turns by that time.
If I recall correctly, the "task" parameter of the task events contains a "time" attribute, which, according to the manual (http://panda3d.org/wiki/index.php/Tasks), "indicates how long this task function has been running since the first execution of the function. The timer is running even when the task function is not being executed". Naturally, this is not quite what you want - you want the time since the last run of the method. The solution that I know is to save the time of the last call in a variable (which I'll call "last time"), and, on each method call, to first subtract "last time" from the current time, store that result in a temporary variable to be used in your calculations for that update, and then replace your "last time" value with the current time, to be used on the next update.
Now, your current system, in which you seem to add and remove your tasks on button presses and releases, presents a problem to this. Offhand, you could either store a boolean value for each task to indicate whether the task has been running or not, and act based on that, or consolidate your updates into a single update task that calculates a single "time since last update" and uses that, checking a set of key-state variables that are set and unset by your key -press and -release events respectively in order to control movement.
A skeletal example of the latter solution might look something like this:
taskMgr.add(self.update, "update")
self.last_time = 0
def update(self, task):
dt = task.time - self.last_time #"dt" is our "time since last udpate"
self.last_time = task.time
if keys["forward"]:
dist_to_move = speed*dt
#Continue with updating your object...
#Go on to update anything else that you want to update...
return Task.cont
01DT!m3r
23-09-2008, 05:27 PM
Thanks :)you OWN! now everything is up and running ! I did find a problem with my map as well ,It was ...well to complicated ,the car was colliding with two points that werent connected and just went crazy:)
Thaumaturge
23-09-2008, 08:51 PM
It's my pleasure - I'm glad to hear that you got things up and running. ^_^
01DT!m3r
26-09-2008, 08:14 PM
Just one more Q and I will(hopefully) be out of your hair ,How do I get my game on other computers?Thanks
Thaumaturge
26-09-2008, 11:03 PM
Heheh, don't worry about it - I'm happy to answer questions. My only concern is that you limit your pool of probable responders by posting here. :P
As to your question, there are three basic ways that I see:
1) Get other people to download Panda, and give them your files. This is, of course, probably not the best course. :P
2) Give people your Python files, resources (models, textures, sounds, etc.) and the DLLs used by your program. This, however, calls for their having Python installed, which is of course not guaranteed by any means. This seems to me to be better than the previous method, but is probably still not the best.
3) Finally, use another program to convert your program to an executable, and give that, and any relevant files (again, both such things as models, textures and sounds and any DLLs used). Panda includes such a program - "Packpanda", if I recall correctly - and I think that there might be instructions on its use in the manual, but I'm not sure; at the least a search of the Panda forums should turn up information. However, I find that this tends to produce rather large packages. Instead, I prefer another program called PyInstaller - it's a little more complicated to use, but is, I think, a better choice for keeping your file sizes down.
Finally, note that if you want to exclude DLLs (and they can, I find, take up a fair bit of space), you might want to look into a dependency-checking program, which should be able to tell you which DLLs are used by your project. I use Dependency Walker (for which I think that this (http://dependencywalker.com/) is the site).
01DT!m3r
28-09-2008, 07:37 PM
Thanks again!you are like the guardian angel of Panda3d:)
Thaumaturge
28-09-2008, 10:08 PM
*chuckles* It's my pleasure, and thank you for the compliment - although I think that it's more that I'm the only other particularly active Panda user here (that I know of, at least). ^_^
Powered by vBulletin® Version 4.2.4 Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.