Collision detection

daedar

07-06-2007 12:47:03

Hi,

let me explain the problem... in our FPS game the player can jump into vehicles like buggies, planes, helicopter,... now, we need to detect when the player crashes his vehicle (into walls, ground,..) so that we can destroy it if needed.

Previously we were using Newton with Collision Callbacks, I was wondering if there is a similar feature with NxOgre? if not I'm thinking of comparing the previous velocity(.length) with the current one (each frame) and if the difference if > to a fixed treshold, this could be because of a collision but it's a little tricky I think and the treshold value could be hard to set.

If anyone has a solution...

Thx :D

betajaen

07-06-2007 13:22:57

This is for 0.9 right?

A "CharacterHitReport" will do the trick. Basically it tells PhysX to allow the character to pass through the hit NxActor or not. In that time you can move the NxActor or do complicated things like your doing. A Character can have more than one HitReporter, so they run through sequentially. They also have control if the others get called or not.

Obviously you don't have to handle the collision response parts yourself, you can leave it up to the other HitReporters.

The CharacterController class handles and stores them for you, unfortantly for some reason there isn't a factory method to store them for you. So for now; Goto NxOgreCharacterController.h, line ~97 and move "CharacterHitReports mHitReports;" to the public section. There you can insert the reporters manually.

Hope this helps.

daedar

07-06-2007 13:53:40

I'll try this, thx betajaen.

Pottej

08-06-2007 17:37:37

Hi Betajaen,

I am trying to add a hit reporter myself right now and I'm having some trouble. I would rather not have to edit the SVN code because there are other people working on my application using your code too, so would rather not have to make them all change it manually.

In your comments you mentioned a addHitReport function in the character controller, but it doesn't seem to be implemented. Is this coming soon or will I have to add it myself?


// Other HitReports are executed first, if they return a true, then rest are not executed.
// class myHitReport : public CharacterHitReport {
// bool onActorHit(Character*, Actor*, Shape*, Group*);
// bool onCharacterHit(Character*, Actor*, Shape*, Group*);
// }
// ...
// mWorld->getCharacterController->addHitReport(new myHitReport);
//


Also I am trying to make a custom character with variable walk speeds and full control over all movement, and I am not totally sure how you intend people to use your framework to do it.

At the moment I have a 'CustomCharacter' class which has to extend NxOgre::Chracter, NxOgre::CharacterMovementVectorController, NxOgre::CharacterHitReport.

So far this is the neatest way I have found to make my own characters, but do you have a cleaner solution in mind?

I would like to register my character as a hit reporter but at the moment I dont know how without editing the NxOgre code base so could you help please?

Cheers mate

pottej

betajaen

08-06-2007 18:24:09

Yes, I do.

1. Don't merge all of those classes into one. For one reason it doesn't make much sense.

CharacterMovementVectorController and CharacterHitReports could be an entire sub-system of your game in total, from handling various walking to running to sprinting speeds of different types of characters depending on the surface that is being walked on or to some sort of game effect (speed multipliers). All of that is way to much for a single Character Class, and there is a specific OO term for it, which escapes me this movement. Your Character class should just contain "what it is" (and of course a pointer to the NxOgre character class) and let the other Classes handle it for you.

2. You'll have to modify CharacterController to do it, I'm afraid. all you have to do is move the HitReporters into the public section, as will all NxOgre containers, you "insert" it in. If you want NxOgre to delete it for you when it shuts down; Perform a "lock" function as well.

Pottej

08-06-2007 19:15:28

Cheers, I originally tried to keep them seperate but had some problems. I think it was because I was directly extending the Character class instead of making my own which contains a pointer to a Character.


I'll let you know how I get on.

daedar

11-06-2007 22:45:28

In fact, I'm not using characters for my vehicles. So I'd like to intercept collisions between bodies or actors... CharacterHitReport is only for characters right?

betajaen

11-06-2007 22:49:09

Yep, Characters to Actors or Actors to Characters.

daedar

11-06-2007 23:12:45

ok so I can't get a callback when an actor/body collides... quite annoying :cry:

betajaen

11-06-2007 23:14:19

Actor to Actor collision? Not yet.

daedar

11-06-2007 23:29:47

Ok but is it planned? that would be really great 8)

betajaen

11-06-2007 23:39:49

Of course it's planned. It's already a big feature in 0.6

You could write your own system, use PhysX directly for actor callbacks. Until at least I've written it.

daedar

11-06-2007 23:53:29

Great!

Yep I think I will do that! Thx for the fast replies betajaen!