Character getentity attaching bone crash

fzh

16-01-2008 15:04:12

hi, i'm trying to attach a weapon to the hand bone of the entity, but when i use the following line, it results in a crash.
mCharacter->getEntity()->attachObjectToBone("Bip01 R Hand",mWeapon);
This is after the entity is attached to the character.

However, if I attach the weapon to the entity bone, then attaching the entity to the character, it works fine. I'm wondering what could be causing the problem, since although this method works for now, I might need to switch the weapon later on and requires the earlier method of calling the entity from the character class. Thank you.

Also, i'm using mCharacter->getNode()->attachObject(charEntity); to attach the entity, could it be that due to this getEntity from Character class does not return the entity?

betajaen

16-01-2008 15:40:40

Most likely, all it's doing is returning the mEntity in Character.

fzh

17-01-2008 04:27:58

thanks for the reply, I figure that should be the problem, not really a big deal after thinking about it since I could just call the pointer to the entity in my class that encapsulates Character class instead.

There is another question, after looking through the forum, I deduced that to implement collision detection for the weapon, I could either use a body for the weapon and attach it to the character via a joint, or have an actor for the weapon and adjust it to the position and orientation of the weapon entity every frame. I'm wondering which method would be better, and are there any potential problems, since the weapon bounding box would probably intersect with the character bounding box affecting collision detection.

betajaen

17-01-2008 11:03:17

There are a few ways to do this. So I'm going to type them up in no particular order.

- Normal actor, attached to the NxActor in the Character using a joint.
- Floating kinematic actor.
- A NxCharacter (it has been done before).

With the actor you could use dominance group feature in the later versions of PhysX so when the sword swings around or catches something, that something doesn't get knocked over, and you can specific a specific collision group or fiddle around with the character collision code (in NxOgre) so the sword and character don't go all funny.

It's up to you if you use a body or an actor. I would use an Actor and manually adjust it when the hand changes, almost like an inverse ragdoll.

fzh

18-01-2008 04:01:03

So i'm using this line to attach the weapon actor to the character actor
NxOgre::Joint *mJoint = mSceneMgr->createSphericalJoint((NxOgre::Actor*)mCharacter->getNxController()->getActor(),weaponActor,mWeapon->getParentNode()->getPosition());
Where mWeapon is the entity of the weapon, mSceneMgr is the NxOgre scene, rest should be self explanatory.
I need to typecast the NxActor to Actor in character else it returns a type def error, however, it crashes showing an error of somewhere in NxOgre scene, so it has to be due to the type casting. Is it supposed to be done this way? If not, how do I join the NxActor in character to the weapon actor?

betajaen

18-01-2008 09:23:18

You can't cast NxActor into Actors like that. They are totally unrelated, it's like casting a Ogre SceneNode into a Ogre ColourValue.

You should create the joint by hand using the PhysX classes. Use weaponActor->getNxActor() as the first actor and mCharacter->getNxController()->getActor() for the second.

fzh

18-01-2008 10:50:01

yes, i realised it was really silly lol, thought it would work magically. Thanks for the tip, i'll try it now.

fzh

20-01-2008 06:58:20

ok, so I used the following code to create the joint joining the weapon and character actor. I'm wondering if there's anything wrong, since the physX remote debugger shows that both the weapon actor and the joint does not exist. There is also no effect in the game due to supposedly added weapon actor even though I didn't setup the dominance group yet, and the collision group allows for collision between weapon and character as well.

weaponActor = mSceneMgr->createActor(mName+"wActor",new NxOgre::CubeShape(size.x,size.y,size.z),Vector3(0,0,0),"mass: 100, Group: tW");

NxSphericalJointDesc sphericalDesc;
sphericalDesc.setToDefault();
sphericalDesc.actor[0] = weaponActor->getNxActor();
sphericalDesc.actor[1] = mCharacter->getNxController()->getActor();
sphericalDesc.setGlobalAnchor(NxVec3(mWeapon->getParentNode()->getPosition().x,mWeapon->getParentNode()->getPosition().y,mWeapon->getParentNode()->getPosition().z));
sphericalDesc.setGlobalAxis(NxVec3(0,1,0));

NxSphericalJoint *sphericalJoint = (NxSphericalJoint*)mSceneMgr->getNxScene()->createJoint(sphericalDesc);



There's some other questions on collision callback.
1.Does it work well with character class and actor collision?
2.In function onTouch(Actor *a, Actor *b) and the call actor->setCallback(mCallback); is actor a the caller of the callback or actor b?
3.How do I get the point of collision in the onTouch function with the 2 actor pointers given. Do I create a contact pair and iterate to get the point?
4.Is using a name system the usual method for collision response? I'm thinking of getting the name of the actors in collision, then getting the custom character class from scene with same name and apply the results. However it seems to be very clumsy and messy and I'm wondering if there are better existing methods to do this.

betajaen

20-01-2008 11:34:50

PhysX usually returns a NULL if it doesn't like the description of something. See if sphericalJoint is NULL before you check anything else. It could be due to actor[0] being a character actor or it's kinematic.

Now for your questions:

1. Yep. There are separate functions for actor-actor and character-actor callbacks (and in the future character-character).

2. It depends who PhysX thinks hit first. You have to check.

3. I believe I've adjusted the collision callback to include contact pair information, but I can't remember in which NxOgre. It's probably in bleeding.

4. You can just use the pointers of the Actor and Characters. I do that and it's quite efficient. If you prefer to use hashes or another type of identification you can sub-class Actor like body does and use your own (obviously you'd have to keep the string). However the most easiest way is just to keep a copy of the Actor and Character pointer within the callback class and just compare the pointers.

fzh

20-01-2008 11:46:06

Thanks for the reply.

ok I tried using the character controller hitreport from this thread: http://www.ogre3d.org/phpBB2addons/view ... n&start=15

testing it with this code:
class myHitReport : public NxOgre::CharacterHitReport {

CharacterHitReport::Response onActor(NxOgre::Character* mChar, Actor* mActor, Shape* mShape, ActorGroup* mAGroup, const NxControllerShapeHit&) {
return NxOgre::CharacterHitReport::RS_None;

}

CharacterHitReport::Response onCharacterHit(Character* mChar, Actor* mActor, Shape* mShape, ActorGroup* mAGroup, const NxControllerShapeHit&) {
return NxOgre::CharacterHitReport::RS_None;
}
};


and registered the character controller with
mHitReport = new myHitReport();
mWorld->getCharacterController()->addHitReport(mHitReport);


However, my character is not falling through the ground, and everything else still remains the same.

fzh

20-01-2008 13:27:39

also, should I be using character controller hit report, or inheriting collision callback?

fzh

21-01-2008 00:54:32

hmm ok i've tried both hitreport and collision callback, but none of them registers a collision when collision occurs. I'm wondering what could be some common errors that will cause such problems?

fzh

21-01-2008 12:37:26

ok, thanks for all the help, I got everything working now. The weapon actor was because I didn't initialize the actor position to that of the joint therefore they are flying all over, turns out that physx won't set it for you at joint creation. For collision callback, it's because it doesn't work with character, and for hit report, because i classified the actor in characters into actor groups, which I probably shouldn't be doing. Wondering if there's a character group feature, since I can't find anything about it in physX documentation.