CFuncMoveLinear Fix: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(First release)
 
(This fix has been expanded in another, better-known article)
 
Line 1: Line 1:
This is a fix for the [[func_movelinear]] entity, specifically when parenting it to something else.
#REDIRECT [[CFuncMoveLinear ParentingFix]]
{{Note|This has not been thoroughly tested, but it seems to work fine (will re-upload if more bugs arise).}}
{{Note|There is still the problem of using the SetParent input, but I am currently investigating this.}}
 
== func_movelinear.cpp ==
 
Lines 86-88 (87-89 in the OB code) in func_movelinear.cpp look like this:
<source lang=cpp> m_vecPosition1 = GetAbsOrigin() - (m_vecMoveDir * m_flMoveDistance * m_flStartPosition);
m_vecPosition2 = m_vecPosition1 + (m_vecMoveDir * m_flMoveDistance);
m_vecFinalDest = GetAbsOrigin();
</source>
Change them to look like this:
<source lang=cpp> m_vecPosition1 = GetLocalOrigin() - (m_vecMoveDir * m_flMoveDistance * m_flStartPosition);
m_vecPosition2 = m_vecPosition1 + (m_vecMoveDir * m_flMoveDistance);
m_vecFinalDest = GetLocalOrigin();
</source>
 
Originally, the start & end positions would be calculated in absolute (world) space. These positions never move (even if the entity's parent does), and can cause movement problems. The start & end positions are now calculated in local (parent) space. Thus, when the parent moves, the entity will also move properly.
 
[[Category:Free source code|A]]

Latest revision as of 12:04, 17 December 2019