Talk:Point viewcontrol

From Valve Developer Community
Revision as of 08:59, 17 August 2006 by Ndnichols (talk | contribs) (Updated for 8/06 SDK update.)
Jump to navigation Jump to search

Update August 17th, 2006: The Camera-Not-Looking-At-Target bug has been fixed in the SDK release at the beginning of August, 2006. The other two bugs are still present, however, and the fixes below still apply.

Camera won't look at target

Update: This bug was corrected in the 8/2006 SDK update.

There is a bug with the camera pointing at the targetted entity. Currently (8/9/06) the camera always points to the origin when a target is set. To fix this, go into the code and open triggers.cpp. Starting at line 2892, the code looks like

if ( m_iAttachmentIndex )
{
 	Vector vecOrigin;
	m_hTarget->GetBaseAnimating()->GetAttachment( m_iAttachmentIndex, vecOrigin );
	VectorAngles( vecOrigin - GetLocalOrigin(), vecGoal );
}
else
{
	if ( m_hTarget )
	{
		VectorAngles( m_hTarget->GetLocalOrigin() - GetLocalOrigin(), vecGoal );
	}
	else
	{
		// Use the viewcontroller's angles
		vecGoal = GetAbsAngles();
	}
}

Change the code to be this:

if ( m_iAttachmentIndex )
{
	Vector vecOrigin;
	m_hTarget->GetBaseAnimating()->GetAttachment( m_iAttachmentIndex, vecOrigin );
	VectorAngles( vecOrigin - GetAbsOrigin(), vecGoal ); //Changed to use AbsOrigin
}
else
{
	if ( m_hTarget )
	{
		VectorAngles( m_hTarget->GetAbsOrigin() - GetAbsOrigin(), vecGoal ); //Changed to use AbsOrigin
	}
	else
	{
		// Use the viewcontroller's angles
		vecGoal = GetAbsAngles();
	}
}

--Ndnichols 20:42, 9 Aug 2006 (PDT)

Camera won't follow path correctly

There is an apparent bug with getting the camera to follow the path_controls set up for it. To fix this, go to triggers.cpp and do the following. To the declaration of CTriggerCamera, add the following private member:

Vector m_vecLastPos;

and also declare it with the DEFINE_FIELD macro (I believe this is necessary for the camera to save and load properly.)

DEFINE_FIELD( m_vecLastPos, FIELD_VECTOR),

In CTriggerCamera::Enable() is the code block

if ( m_pPath )
{
	if ( m_pPath->m_flSpeed != 0 )
		m_targetSpeed = m_pPath->m_flSpeed;
	
	m_flStopTime += m_pPath->GetDelay();
}

Change this block to be

if ( m_pPath )
{
	if ( m_pPath->m_flSpeed != 0 )
		m_targetSpeed = m_pPath->m_flSpeed;
	
	m_flStopTime += m_pPath->GetDelay();
	m_vecMoveDir = m_pPath->GetLocalOrigin() - GetLocalOrigin();
	m_moveDistance = VectorNormalize( m_vecMoveDir );
	m_flStopTime = gpGlobals->curtime + m_pPath->GetDelay();
}
else
{
	m_moveDistance = 0;
}

Near the end of the Enable() function is the line

m_moveDistance = 0;

Change this to be

m_vecLastPos = GetAbsOrigin();

Now, in the CTrigger::Move() function, change the line that reads

m_moveDistance -= m_flSpeed * gpGlobals->frametime;

to read

m_moveDistance -= VectorNormalize(GetAbsOrigin() - m_vecLastPos);

Finally, add the line

m_vecLastPos = GetAbsOrigin();

to the very end of the Move() function.

(I believe the two bugs were that m_moveDistance wasn't being calculated properly in Enable(), and that the m_flSpeed * gpGlobals->frametime expression reported moving much farther than actually happened. This caused the camera to think it had arrived at the destination camera before it actually had.)

I haven't tested this extensively at all, but it seems to work for me. Please let me know if you have any issues. --Ndnichols 13:09, 10 Aug 2006 (PDT)

Teleport spawnflag on path_corner doesn't do anything for camera

The point_viewcontrol currently ignores the "Teleport to THIS path_corner" spawn flag on a path_corner. To fix, this, go to line 2533 in trigger.cpp (right after the SF_CAMERA_PLAYER_* #defines and add the line

#define SF_PATHCORNER_TELEPORT 2

Now, go to the line that decreases m_moveDistance. It begins with

m_moveDistance -= 

near the beginning of CTriggerCamera::Move(). (The actual line depends on whether or not you have changed it as per the above bug-fixes.) Regardless, change the code from

m_moveDistance -= VectorNormalize(GetAbsOrigin() - m_vecLastPos);

to

if (m_pPath->GetSpawnFlags() & SF_PATHCORNER_TELEPORT)
{
	SetAbsOrigin(m_pPath->GetAbsOrigin());
	m_moveDistance = -1;  //Make sure we enter the conditional below and advance to the next corner.
}
else
{	
	// Subtract movement from the previous frame
	m_moveDistance -= VectorNormalize(GetAbsOrigin() - m_vecLastPos);
}

If you're working on with a .VCD script with camera movements (presumably fired with triggers from the scene) it can be convenient to put a path_corner at the camera's starting position that the camera teleports to. This ensures that if you modify the scene and reload it without exiting HL2, the camera will always start at the correct point (and not wherever it ended up with after the previous completion of the scene.) --Ndnichols 11:18, 12 Aug 2006 (PDT)

ETC.

The camera won't fall path_corners without having a "look at" target set. This is because the think function is only being set if m_hTarget is valid. Just give the camera something to look at, and it should work fine. --Ndnichols 10:11, 12 Aug 2006 (PDT)