Hi all,
I’ve been working on a problem with creating and spawning a spherical
vphysics object for the last 4 days, and can’t get it to work.
The basic idea is that I have a simple logical map entity linked to the
class “CBall_Spawn”. This has a function that, when called will create
an entity of the type “CBall” at the origin of “CBall_Spawn” with a
specified initial velocity.
Now, with the code I have, the ball will spawn, but will fall through
the floor as if it isn’t there. I have tried all sorts of different
combinations for initialising the ball and its physical properties, but
none of them have worked. I would be extremely grateful if you would
take a look at the code and see if I’m doing something obvious wrong,
because to be honest, I have run out of ideas.
Thanks in advance,
Phil
-----------------------------------------------------------------------------------------------------------------------
This is the relevant code from CBall_Spawn.
-----------------------------------------------------------------------------------------------------------------------
void CBall_Spawn::Spawn()
{
m_vAbsPosition = this->GetAbsOrigin();
m_vStartingVelocity = Vector (m_fXVelocity, m_fYVelocity, m_fZVelocity);
//these values are taken from fields in the Hammer entity
Spawn_Ball();
}
-----------------------------------------------------------------------------------------------------------------------
void CBall_Spawn::Spawn_Ball()
{
//Spawn ball at absolute origin with starting velocity as set by map entity
CBall* p_Ball = CBall::Create(m_vAbsPosition, m_angStartingAngle,
m_vStartingVelocity, NULL);
}
-----------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------
And this is the code for CBall. The model I am using is one I have
created, but I have tried it with others and it makes no difference.
-----------------------------------------------------------------------------------------------------------------------
CBall* CBall::Create( const Vector &vecOrigin, const QAngle &vecAngles,
const Vector &vecVelocity, edict_t *pentOwner = NULL)
{
CBall *pBall = (CBall *) CBaseEntity::CreateNoSpawn( "graviball",
vecOrigin, vecAngles, CBaseEntity::Instance( pentOwner ) );
pBall->SetOwnerEntity (Instance(pentOwner));
pBall->Spawn();
pBall->ApplyAbsVelocityImpulse( vecVelocity );
return pBall;
}
-----------------------------------------------------------------------------------------------------------------------
void CBall::Spawn(void)
{
Precache();
SetModel( ENTITY_MODEL);
if (!CreatePhysics())
{
Warning("Could not create physics for %s\n", GetDebugName());
}
} // End CBall Spawn function
-----------------------------------------------------------------------------------------------------------------------
void CBall::Precache(void)
{
PrecacheModel( ENTITY_MODEL );
BaseClass::Precache();
} // End CBall Precache function
-----------------------------------------------------------------------------------------------------------------------
bool CBall::CreatePhysics()
{
solid_t tmpSolid;
tmpSolid.params = g_PhysDefaultObjectParams;
tmpSolid.params.mass = 20.0f;
tmpSolid.params.inertia = 0.05f;
tmpSolid.params.rotdamping = 1.0;
tmpSolid.params.damping = 0.85;
tmpSolid.params.dragCoefficient = 0.1;
tmpSolid.params.pGameData = this;
IPhysicsObject *pPhysics = VPhysicsGetObject();
if(pPhysics)
VPhysicsDestroyObject();
pPhysics = NULL;
pPhysics = physenv->CreateSphereObject( 16.0f,
physprops->GetSurfaceIndex( tmpSolid.surfaceprop ), GetAbsOrigin(),
GetAbsAngles(), &tmpSolid.params, false );
if (!pPhysics)
{
DevMsg("graviball: couldn't create sphere object..\n");
return false;
}
SetMoveType(MOVETYPE_VPHYSICS);
SetSolid(SOLID_VPHYSICS);
VPhysicsSetObject(pPhysics);
pPhysics->EnableCollisions(true); //start without collisions
pPhysics->EnableMotion( true );
pPhysics->Wake(); //Tony; start asleep
return true;
}
_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives, please
visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders