RigidBody2D::RigidBody2D(const RigidBody2D& other, Object& newObj) : Collider2D(other, newObj) { b2BodyDef bd; b2FixtureDef fdf; auto& pos = getObject()->getGlobalPosition(); bd.angle = glm::eulerAngles(getObject()->getGlobalRotation()).z; bd.position = b2Vec2(pos.x, pos.y); bd.userData = this; auto om = other.m_body; bd.type = om->GetType(); newObj.setIgnoreParent(other.getObject()->ignoresParent()); fdf.isSensor = om->GetFixtureList()->IsSensor(); bd.allowSleep = om->IsSleepingAllowed(); m_body = other.m_worldRef2D.m_worldData2D->CreateBody(&bd); auto omf = om->GetFixtureList(); fdf.filter = omf->GetFilterData(); fdf.friction = omf->GetFriction(); fdf.restitution = omf->GetRestitution(); fdf.shape = omf->GetShape(); fdf.density = omf->GetDensity(); m_body->CreateFixture(&fdf); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CHarpoon::HarpoonTouch( CBaseEntity *pOther ) { // If we've stuck something, freeze. Make sure we hit it along our velocity. if ( pOther->GetCollisionGroup() != TFCOLLISION_GROUP_SHIELD ) { // Perform the collision response... const trace_t &tr = CBaseEntity::GetTouchTrace( ); Vector vecNewVelocity; PhysicsClipVelocity (GetAbsVelocity(), tr.plane.normal, vecNewVelocity, 2.0 - GetFriction()); SetAbsVelocity( vecNewVelocity ); } else { // Move away from the shield... // Fling it out a little extra along the plane normal Vector vecCenter; AngleVectors( pOther->GetAbsAngles(), &vecCenter ); Vector vecNewVelocity; VectorMultiply( vecCenter, 400.0f, vecNewVelocity ); SetAbsVelocity( vecNewVelocity ); } if ( !pOther->IsBSPModel() && !pOther->GetBaseAnimating() ) return; // At this point, it shouldn't affect player movement SetCollisionGroup( COLLISION_GROUP_DEBRIS ); // Remove myself soon SetThink( SUB_Remove ); SetNextThink( gpGlobals->curtime + 30.0 ); m_hImpaledTarget = pOther; // Should I impale something? if ( pOther->GetBaseAnimating() ) { CheckLinkedHarpoon(); if ( pOther->GetMoveType() != MOVETYPE_NONE ) { ImpaleTarget( pOther ); return; } } CheckLinkedHarpoon(); EmitSound( "Harpoon.Impact" ); // Stop moving SetMoveType( MOVETYPE_NONE ); }
void Humanoid::Update() { // CHANGED // making the humanoid call the character's update so that knockback and AI get applied // Rolf, 6-13-04 Character::Update(); // CHANGED // optimization: entities that are out of sight and far away do nothing if (!RContext->bInCameraFrustum && RContext->fDistSquared > 1000) return; float fDebugGroundHeight=0; Vector vDebugGroundNorm(0, 1, 0); HandleInput(); Vector vDeccel(vInternal); //(friction) //find friction if (!vDeccel.IsZeroVector()) vDeccel=vDeccel/GetFriction()*Timer::GetElapsedTime(); vDeccel.fComp[1]=0.0f; vDeccel *= - 1.0f; //add friction if(vInternal.LengthSquared()<vDeccel.LengthSquared()) vInternal.SetToZero(); else vInternal += vDeccel; //add gravity vExternal += Game::pWorld->vGravity*Timer::GetElapsedTime(); vVelocity= vInternal + vExternal; MoveBy(vVelocity * Timer::GetElapsedTime()); RTF.mGlobal=mGlobal; // hack: ground clamp here to avoid jittery effect // version 1: geometry-level collision response // good for steep surfaces, bad for flat ones and high falling rates // version 2: ground clamp // fast and good for smooth terrain, but goes through walls if (Game::pWorld->GroundClamp (this)) { vExternal.fComp[1] = 0; bJump = 1; } else bJump = 0; /* // version 1: geometry level collision response Sphere middleOfObject (GetPos(), fWidth); if (Game::pWorld->CollisionClamp (Sphere (GetPos(), fWidth))) { MoveTo (middleOfObject.mGlobal.GetPos()); vExternal.fComp[1] = 0; bJump = 1; } else bJump = 0; */ /* // version 3: hybrid // tries to be the best of 1 and 2 combined, but is expensive Vector vGroundPoint(0,0,0); //for ground clamping Triangle tGround; //for ground clamping Vector vIntersectPoint (0,0,0); //for geometry-level collision Triangle tIntersect; //for geometry-level collision Line lGoingDown (GetPos() + Vector (0, 0.4f * fHeight, 0), GetPos() - Vector (0, 0.6f * fHeight, 0)); bool bGroundColl, bGeometryColl; // use the ground clamping version of collision detection, since it is more robust if ( (bGroundColl = Game::pWorld->CollidesWithGeometry (lGoingDown, &vGroundPoint, &tGround)) || (bGeometryColl = Game::pWorld->CollidesWithGeometry (this, &vIntersectPoint, &tIntersect))) { // use geometry level collision response for steep terrain if (bGeometryColl && tIntersect.vNormal.fComp[1] < 0.5f) { pBoundingShape->CollisionClamp (vIntersectPoint); MoveTo (pBoundingShape->GetPos()); } // use ground clamping collision response for flat terrain else { MoveTo (vGroundPoint + Vector (0, fHeight * 0.5f, 0)); vExternal.fComp[1] = 0; bJump = 1; } } else bJump = 0; */ }