mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-05 11:15:34 +00:00
Merge branch 'setpos' into 'master'
Unbreak SetPos and the mods using it (#5919) See merge request OpenMW/openmw!696
This commit is contained in:
commit
582f1503c1
2 changed files with 18 additions and 3 deletions
|
@ -123,6 +123,7 @@ void Actor::updatePosition()
|
|||
mSimulationPosition = mWorldPosition;
|
||||
mStandingOnPtr = nullptr;
|
||||
mSkipSimulation = true;
|
||||
mPositionOffset = osg::Vec3f();
|
||||
}
|
||||
|
||||
void Actor::updateWorldPosition()
|
||||
|
@ -179,9 +180,9 @@ bool Actor::setPosition(const osg::Vec3f& position)
|
|||
if (mSkipSimulation)
|
||||
return false;
|
||||
bool hasChanged = mPosition != position || mPositionOffset.length() != 0 || mWorldPositionChanged;
|
||||
mPreviousPosition = mPosition + mPositionOffset;
|
||||
mPosition = position + mPositionOffset;
|
||||
mPositionOffset = osg::Vec3f();
|
||||
applyOffsetChange();
|
||||
mPreviousPosition = mPosition;
|
||||
mPosition = position;
|
||||
return hasChanged;
|
||||
}
|
||||
|
||||
|
@ -198,6 +199,7 @@ void Actor::applyOffsetChange()
|
|||
mWorldPosition += mPositionOffset;
|
||||
mPosition += mPositionOffset;
|
||||
mPreviousPosition += mPositionOffset;
|
||||
mSimulationPosition += mPositionOffset;
|
||||
mPositionOffset = osg::Vec3f();
|
||||
mWorldPositionChanged = true;
|
||||
}
|
||||
|
|
|
@ -862,6 +862,19 @@ namespace MWWorld
|
|||
if (reference == getPlayerPtr())
|
||||
throw std::runtime_error("can not disable player object");
|
||||
|
||||
// A common pattern to teleport NPC in scripts is a sequence of SetPos/Disable/Enable
|
||||
// Disable/Enable create a new physics actor, and so the SetPos call is lost
|
||||
// Call moveObject so that the newly created physics actor will have up-to-date position
|
||||
if (reference.getClass().isActor())
|
||||
{
|
||||
auto* physactor = mPhysics->getActor(reference);
|
||||
if (physactor)
|
||||
{
|
||||
physactor->applyOffsetChange();
|
||||
const auto position = physactor->getSimulationPosition();
|
||||
moveObject(reference, position.x(), position.y(), position.z(), true);
|
||||
}
|
||||
}
|
||||
reference.getRefData().disable();
|
||||
|
||||
if (reference.getCellRef().getRefNum().hasContentFile())
|
||||
|
|
Loading…
Reference in a new issue