Talk:Point viewcontrol

From Valve Developer Community
Revision as of 10:06, 17 August 2006 by Ndnichols (talk | contribs)
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.

Bugs

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)

Additional Features

Camera Stack

Currently, if you have one viewcontrol A enabled, then enable viewcontrol B, then disable B, the view will be reset to the player (not A.) This makes it difficult to go from one camera to another and back without carefully timed enables and disables. It is easy to change this behaviour, though, and have a viewcontrol "stack". Each successively enabled viewcontrol will add a camera to the "stack", and when the top of the stack is popped (by disabling the top camera), view will return to the viewcontrol that is now at the top of the stack. Please note that if you disable cameras out of order (ie, enable A, enable B, disable A) things will get weird and out-of-sync; so, always make sure to disable the most recently enabled camera. Now, after all that explanation is the implementation; this is one of those things that's easier to code than it is to discuss. (The gist is that when a camera is enabled, it stores the player's current ViewEntity; when the camera is disabled, then, we set the player's view entity to be the previous view entity, and not automatically the player.)

Open triggers.cpp, and add the following private declaration to CTriggerCamera:

CBaseEntity* m_pPrevViewEntity;

and make sure to add it with the DEFINE_FIELD macro as well:

DEFINE_FIELD( m_pPrevViewEntity, FIELD_CLASSPTR ),

Now, in the enable function, just before the line where you set the ViewEntity:

((CBasePlayer*)m_hPlayer.Get())->SetViewEntity( this );

add the line

m_pPrevViewEntity = ((CBasePlayer*)m_hPlayer.Get())->GetViewEntity(); // Store the current view entity

Now, in the disable function