CollisionRay and collision intersection

I’ve searched around and looked at the Panda3D API, but can’t find a method of reading the current collision intersection for a CollisionRay.

I am using a CollisionHandlerEvent in my app, which does not allow you to use the methods in Ralph for ensuring your avatar maintains contact with the ground/terrain. So, I’m looking for a way to read the current collision intersection of the existing CollisionRay attached to the avatar model, and use that data to set the Z position of the avatar.

I was looking in to CollisionHandlerFloor but I want to be able to modify how the collision with the floor is handled and perform specific tasks under certain conditions instead of just moving the avatar to the collision Z.

I’d like to keep the collision system eventbased as opposed to queue based, so if anyone can point me to a reference that explains how to read the collision intersection of a given CollisionRay I’d appreciate it.

Thanks,

Mike

The function that receives the collision event accepts one parameter, which will be a CollisionEntry object. That object contains all the information there is to know about the collision event itself.

David

David:

Thanks. Yep, I knew that much. My issue is that I need to determine the Z intersection at which the CollisionRay is hitting the terrain, even when the avatar is not colliding with the floor. In this circumstance there is no collision event occurring because the avatar is not colliding with the floor, and therefore no collision entry to read.

Is there a method of pulling the current collision intersection from the CollisionRay object itself?

Sorry, I don’t understand. Is there a collision or isn’t there?

There is no such thing as a “current” collision associated with a CollisionRay. A CollisionRay is just a ray; it has no associated collisions. Collision events are detected and reported by the collision traverser; they do not exist beyond that.

When you say “the avatar is not colliding with the floor”, you really mean his CollisionRay isn’t colliding with the floor, right? But if that’s the case, then what collision data are you hoping to retrieve?

David

Hi David. What I am trying to do is use the Z axis of the collision intersection to set the avatar on the ground. however, using event-based collision handling means that if there is no collision event there is no entry to use to ensure the avatar is on the ground. If I walk my avatar off a hill, for example, there is no collision with the ground and the avatar simply moves through the air because there is no collision data to reference where the avatar should be placed on the Z axis. Make sense?

What I was trying to ask for is a method to read a CollisionRay to determine where it intersects with the terrain. This could be used to determine how high an avatar is off the ground, but I can’t find an obvious way of reading this data.

As a work around I just switched my app over to using the queue based collision handler just like Ralph, although I think I lost some of the flexibility of the event-driver collision handler.

Thanks,

Mike

This task:

is exactly the task that is performed by a CollisionTraverser. So, the way to ask a CollisionRay where it intersects the terrain is to hook it up to a CollisionTraverser and call traverse().

Wait! I think I know what you might be talking about. In an event-based system, you typically listen for “enter” and “exit” events. The “enter” event is sent the first time a collision is detected with a particular object, such as the ground, but then not sent again. So if you are listening for “enter”, you only have a CollisionEntry for the first time you detect the ground.

But there’s also an event sent for “again” events. These events are sent on each subsequent frame that a collision is detected with a particular object. A new CollisionEntry is sent for each of these. So if you are listening for “again” events as well as “enter” events, you can continue to get updated CollisionEntry information every frame.

David

David:

What is happening in my case is that I can move my avatar across a hill just fine. Once the hill begins to drop off, however, there are no more collisions because the avatar is no longer colliding with the ground. My avatar simply continues to move along the X or Y coordinates and appears to float through the air. Because I lost my events I have no reference to tell the avatar to fall to the ground. I hope this makes sense.

I am using base.cTrav = self.collTrav which provides for the automatic calls to traverser each frame.

If you have a CollisionRay pointing straight down, it will continue to get collisions with the ground (assuming there is a ground somewhere below your avatar).

But you do have to add this CollisionRay to your traverser and listen for the events it generates.

David

Yep, I got it. I couldn’t figure out why my avatar would encounter collisions at the top of a hill, and after moving down to flat terrain the collisions would stop (and the ray would disappear). turns out that by using flattenLight() it resolves the issue.

Thanks for your help. Much appreciated.

Now I just have to figure out how to prevent my avatar from becoming partially obscured by terrain as I walk up hill. When there is a vertex that is on an angle, and I start going up that angle, setting the Z value to the lower point of the vertex causes the portion of the avatar about the higher point of the vetex to become obscured. I am searching for a way to determine the highest point of a given vertex.

Thanks again!

-Mike