Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //-----------------------------------------------------------------------------
- // Purpose:
- //-----------------------------------------------------------------------------
- void PickupController::HandleInteraction()
- {
- #ifndef LEADWERKS_5
- // If we are holding something, drop whatever we are holding.
- if (HoldingObject())
- {
- if (m_pCarryEntity->GetAABB().IntersectsPoint(GetEntity()->GetPosition(), 0.2f))
- return;
- ForceDropObject();
- return;
- }
- auto pickinfo = PickInfo();
- //if (VR::Enabled()) entity->SetQuaternion(VR::headsetrotation); // HACK: Camera's quat doesn't update with the hmd.
- auto p0 = GetEntity()->GetPosition(true);
- auto p1 = Transform::Point(0, 0, m_flPickDistance, entity, nullptr);
- bool test = entity->GetWorld()->Pick(p0, p1, pickinfo, 0, true, COLLISION_DEBRIS);
- if (!test)
- {
- EmitSoundScript("Use.Deny");
- return;
- }
- #ifdef DEBUG
- m_pEntEndpoint->SetPosition(p1);
- m_pEntEndpoint->Show();
- #endif
- // Use Test:
- if (test)
- {
- #ifdef DEBUG
- m_pEntEndpoint->SetPosition(pickinfo.position);
- m_pEntEndpoint->Show();
- #endif
- if (QueryObject(pickinfo.entity) == true)
- {
- PickupObject(pickinfo.entity);
- }
- else
- {
- // Disable interacting/use for now.
- if (GetEntityKeyValue(pickinfo.entity, "classname") != "")
- {
- auto actor = (BaseActor*)pickinfo.entity->GetActor();
- if (actor != NULL)
- {
- actor->Use(this);
- }
- else
- {
- pickinfo.entity->CallFunction("Use");
- }
- //EmitSoundScript("Use.Success");
- }
- else
- {
- if (pickinfo.entity->CallFunction("Use") == false)
- {
- EmitSoundScript("Use.Deny");
- }
- }
- }
- }
- #else
- // If we are holding something, drop whatever we are holding.
- if (HoldingObject())
- {
- if (m_pCarryEntity->aabb.IntersectsPoint(GetEntity()->GetPosition(), 0.2f))
- return;
- ForceDropObject();
- return;
- }
- auto pickinfo = PickInfo();
- //if (VR::Enabled()) entity->SetQuaternion(VR::headsetrotation); // HACK: Camera's quat doesn't update with the hmd.
- auto p0 = GetEntity()->GetPosition(true);
- auto p1 = TransformPoint(0, 0, m_flPickDistance, GetEntity(), nullptr);
- #ifdef DEBUG
- m_pEntEndpoint->SetPosition(p1);
- m_pEntEndpoint->Show();
- #endif
- // Use Test:
- if (GetEntity()->GetWorld()->Pick(p0, p1, pickinfo, 0, true, COLLISION_DEBRIS))
- {
- #ifdef DEBUG
- m_pEntEndpoint->SetPosition(pickinfo.position);
- m_pEntEndpoint->Show();
- #endif
- if (QueryObject(pickinfo.entity) == true)
- {
- PickupObject(pickinfo.entity);
- }
- else
- {
- // Disable interacting/use for now.
- #if 0
- if (GetEntityKeyValue(pickinfo.entity, "classname") != "")
- {
- auto actor = (BaseActor*)pickinfo.entity->GetActor();
- if (actor != NULL)
- {
- actor->Use(this);
- }
- else
- {
- pickinfo.entity->CallFunction("Use");
- }
- }
- else
- {
- pickinfo.entity->CallFunction("Use");
- }
- #endif
- }
- }
- #endif
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement