mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-30 01:45:33 +00:00
Use hitboxes and focused object for touch spells (bug #3374)
This commit is contained in:
parent
4666a6a0ab
commit
bde1d07d4e
2 changed files with 49 additions and 47 deletions
|
@ -848,7 +848,7 @@ namespace MWPhysics
|
|||
{
|
||||
// First of all, try to hit where you aim to
|
||||
int hitmask = CollisionType_World | CollisionType_Door | CollisionType_HeightMap | CollisionType_Actor;
|
||||
RayResult result = castRay(origin, origin + (orient * osg::Vec3f(0.0f, queryDistance, 0.0f)), actor, targets, 0xff, hitmask);
|
||||
RayResult result = castRay(origin, origin + (orient * osg::Vec3f(0.0f, queryDistance, 0.0f)), actor, targets, CollisionType_Actor, hitmask);
|
||||
|
||||
if (result.mHit)
|
||||
{
|
||||
|
|
|
@ -2761,64 +2761,66 @@ namespace MWWorld
|
|||
{
|
||||
MWMechanics::CreatureStats& stats = actor.getClass().getCreatureStats(actor);
|
||||
|
||||
// Get the target to use for "on touch" effects, using the facing direction from Head node
|
||||
MWWorld::Ptr target;
|
||||
float distance = getActivationDistancePlusTelekinesis();
|
||||
|
||||
osg::Vec3f hitPosition = actor.getRefData().getPosition().asVec3();
|
||||
osg::Vec3f origin = getActorHeadTransform(actor).getTrans();
|
||||
|
||||
osg::Quat orient = osg::Quat(actor.getRefData().getPosition().rot[0], osg::Vec3f(-1,0,0))
|
||||
* osg::Quat(actor.getRefData().getPosition().rot[2], osg::Vec3f(0,0,-1));
|
||||
|
||||
osg::Vec3f direction = orient * osg::Vec3f(0,1,0);
|
||||
osg::Vec3f dest = origin + direction * distance;
|
||||
|
||||
// For AI actors, get combat targets to use in the ray cast. Only those targets will return a positive hit result.
|
||||
std::vector<MWWorld::Ptr> targetActors;
|
||||
if (!actor.isEmpty() && actor != MWMechanics::getPlayer())
|
||||
actor.getClass().getCreatureStats(actor).getAiSequence().getCombatTargets(targetActors);
|
||||
|
||||
// For actor targets, we want to use bounding boxes (physics raycast).
|
||||
// This is to give a slight tolerance for errors, especially with creatures like the Skeleton that would be very hard to aim at otherwise.
|
||||
// For object targets, we want the detailed shapes (rendering raycast).
|
||||
// If we used the bounding boxes for static objects, then we would not be able to target e.g. objects lying on a shelf.
|
||||
const float fCombatDistance = getStore().get<ESM::GameSetting>().find("fCombatDistance")->getFloat();
|
||||
|
||||
MWPhysics::PhysicsSystem::RayResult result1 = mPhysics->castRay(origin, dest, actor, targetActors, MWPhysics::CollisionType_Actor);
|
||||
osg::Vec3f hitPosition = actor.getRefData().getPosition().asVec3();
|
||||
|
||||
MWRender::RenderingManager::RayResult result2 = mRendering->castRay(origin, dest, true, true);
|
||||
// for player we can take faced object first
|
||||
MWWorld::Ptr target;
|
||||
if (actor == MWMechanics::getPlayer())
|
||||
target = getFacedObject();
|
||||
|
||||
float dist1 = std::numeric_limits<float>::max();
|
||||
float dist2 = std::numeric_limits<float>::max();
|
||||
// if the faced object can not be activated, do not use it
|
||||
if (!target.isEmpty() && !target.getClass().canBeActivated(target))
|
||||
target = NULL;
|
||||
|
||||
if (result1.mHit)
|
||||
dist1 = (origin - result1.mHitPos).length();
|
||||
if (result2.mHit)
|
||||
dist2 = (origin - result2.mHitPointWorld).length();
|
||||
|
||||
if (result1.mHit)
|
||||
if (target.isEmpty())
|
||||
{
|
||||
target = result1.mHitObject;
|
||||
hitPosition = result1.mHitPos;
|
||||
if (dist1 > getMaxActivationDistance() && !target.isEmpty() && (target.getClass().isActor() || !target.getClass().canBeActivated(target)))
|
||||
target = NULL;
|
||||
}
|
||||
else if (result2.mHit)
|
||||
{
|
||||
target = result2.mHitObject;
|
||||
hitPosition = result2.mHitPointWorld;
|
||||
if (dist2 > getMaxActivationDistance() && !target.isEmpty() && !target.getClass().canBeActivated(target))
|
||||
target = NULL;
|
||||
}
|
||||
// For actor targets, we want to use hit contact with bounding boxes.
|
||||
// This is to give a slight tolerance for errors, especially with creatures like the Skeleton that would be very hard to aim at otherwise.
|
||||
// For object targets, we want the detailed shapes (rendering raycast).
|
||||
// If we used the bounding boxes for static objects, then we would not be able to target e.g. objects lying on a shelf.
|
||||
std::pair<MWWorld::Ptr,osg::Vec3f> result1 = getHitContact(actor, fCombatDistance, targetActors);
|
||||
|
||||
// When targeting an actor that is in combat with an "on touch" spell,
|
||||
// compare against the minimum of activation distance and combat distance.
|
||||
// Get the target to use for "on touch" effects, using the facing direction from Head node
|
||||
osg::Vec3f origin = getActorHeadTransform(actor).getTrans();
|
||||
|
||||
if (!target.isEmpty() && target.getClass().isActor() && target.getClass().getCreatureStats (target).getAiSequence().isInCombat())
|
||||
{
|
||||
distance = std::min (distance, getStore().get<ESM::GameSetting>().find("fCombatDistance")->getFloat());
|
||||
if (distance < dist1)
|
||||
target = NULL;
|
||||
osg::Quat orient = osg::Quat(actor.getRefData().getPosition().rot[0], osg::Vec3f(-1,0,0))
|
||||
* osg::Quat(actor.getRefData().getPosition().rot[2], osg::Vec3f(0,0,-1));
|
||||
|
||||
osg::Vec3f direction = orient * osg::Vec3f(0,1,0);
|
||||
float distance = getMaxActivationDistance();
|
||||
osg::Vec3f dest = origin + direction * distance;
|
||||
|
||||
MWRender::RenderingManager::RayResult result2 = mRendering->castRay(origin, dest, true, true);
|
||||
|
||||
float dist1 = std::numeric_limits<float>::max();
|
||||
float dist2 = std::numeric_limits<float>::max();
|
||||
|
||||
if (!result1.first.isEmpty() && result1.first.getClass().isActor())
|
||||
dist1 = (origin - result1.second).length();
|
||||
if (result2.mHit)
|
||||
dist2 = (origin - result2.mHitPointWorld).length();
|
||||
|
||||
if (!result1.first.isEmpty() && result1.first.getClass().isActor())
|
||||
{
|
||||
target = result1.first;
|
||||
hitPosition = result1.second;
|
||||
if (dist1 > getMaxActivationDistance())
|
||||
target = NULL;
|
||||
}
|
||||
else if (result2.mHit)
|
||||
{
|
||||
target = result2.mHitObject;
|
||||
hitPosition = result2.mHitPointWorld;
|
||||
if (dist2 > getMaxActivationDistance() && !target.isEmpty() && !target.getClass().canBeActivated(target))
|
||||
target = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
std::string selectedSpell = stats.getSpells().getSelectedSpell();
|
||||
|
|
Loading…
Reference in a new issue