Constraints

Grab your favourite IDE and tinker with the innards of game engines

Constraints

Postby audryzas on Thu Jul 01, 2010 4:33 pm

Hello, me again. I'm getting headaches once again.

I'm trying to simulate rope constraint, and yet i did, problem is parenting. Ok so i got a fishing rod that has a bobber working fine, but theres some problems, i need a rod to be parented to the player, while in source constraints that are parented to something glichout and don't work at all. So i figured out way to bypass this, and it seems it should work, but the game keeps crashing with debugger saying completely wrong things, like missing pointers, for pointers that exist but i do not use them in that piece of code at all! Theres more bugs like models tend to crash, even though they have vphys model and everything.

Ok so i got a bobber tied to entity with lengthconstraint, which is what i need, now i need that entity to be constrained to the rod itself, while rod is parented to owners hands, this way should make it glich out less, but i started having doupts while writing this.

Anyways heres my full item spawn code.

Code: Select all
void CPropRod::Spawn( void )
{
   Precache();

   SetModel( ROD_MODEL );

   pBob = ( CPropBob * )CreateEntityByName( "prop_bob" );
   pBob->SetAbsOrigin( GetAbsOrigin());
   pBob->Spawn();
/*   pBob->SetParent( this );
   pBob->SetParentAttachment( "rod_up", "rod_up", false ); */

//#if 0
   CBaseEntity *pAttach = ( CPropBob * )CreateEntityByName( "prop_physics" );
   pAttach->SetAbsOrigin( GetAbsOrigin() + Vector( 0, 0, 25 ) );
   pAttach->SetModel( ROD_MODEL );
   pAttach->Spawn();
   pAttach->AddSolidFlags( FSOLID_NOT_SOLID );
//   pAttach->SetParent( this );
//   pAttach->SetParentAttachment( "rod_up", "rod_up", false );

   CPhysFishingConstraint *pConstraint = ( CPhysFishingConstraint * )CreateEntityByName( "phys_fishingconstraint" );
   pConstraint->SetParent( this );
   //pConstraint->Spawn( pAttach, pBob );
//#endif


   IPhysicsObject *pBodyObject = this->VPhysicsGetObject();
//   Assert( pBodyObject );
   IPhysicsObject *pTailObject = pAttach->VPhysicsGetObject();
//   Assert( pTailObject );
   constraint_fixedparams_t fixed;
   fixed.Defaults();
   fixed.InitWithCurrentObjectState( pTailObject, pBodyObject );
   fixed.constraint.Defaults();
   physenv->CreateFixedConstraint( pBodyObject, pTailObject, NULL, fixed );

   BaseClass::Spawn();
}


The last lines where im trying to create fixed constraint that always fail, funny thing is if i constraint pAttach entity and pBob entity instead of pBob and this(Rod itself) it works, else fails and crashes hl2.exe

Any ideas would be appreaciated.

Or if you have any other way to have rope like constraints that can be parented to player i'd like to hear them.
audryzas
Member
Member
 
Joined: Sun Jun 20, 2010 2:58 pm

Return to Programming

Who is online

Users browsing this forum: No registered users