CFuncMoveLinear Fix

From Valve Developer Community
Jump to: navigation, search

This is a fix for the func_movelinear entity, specifically when parenting it to something else.

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:

	m_vecPosition1 = GetAbsOrigin() - (m_vecMoveDir * m_flMoveDistance * m_flStartPosition);
	m_vecPosition2 = m_vecPosition1 + (m_vecMoveDir * m_flMoveDistance);
	m_vecFinalDest = GetAbsOrigin();

Change them to look like this:

	m_vecPosition1 = GetLocalOrigin() - (m_vecMoveDir * m_flMoveDistance * m_flStartPosition);
	m_vecPosition2 = m_vecPosition1 + (m_vecMoveDir * m_flMoveDistance);
	m_vecFinalDest = GetLocalOrigin();

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.