Multiplayer Vehicle Fixes

From Valve Developer Community
(Redirected from HL2DM Vehicle Fix)
Jump to: navigation, search

These fixes are to correct some issues with using Valves vehicle code in a multiplayer game. A true way of doing vehicles in Source Multiplayer would be to write prediction code for the client, but this is not possible with the current engine. The only other option would be to write your own vehicle movement code, which is no easy task for complicated vehicles like the buggy. Research was made into the possibility of predicted physics simulations between the server and client with poor results. Half-Life 2 Rally closed 27 Dec 2006 and has written a list of critical problems they experienced here.

Laggy Vehicle View

A couple of changes will fix the laggy view, but present different issues. One being the cameras position no longer interpolating to where it should.

Open cl_dll/c_prop_vehicle.cpp

Find C_PropVehicleDriveable::C_PropVehicleDriveable() constructor.

Replace

	m_ViewSmoothingData.bDampenEyePosition = true;

with

	m_ViewSmoothingData.bDampenEyePosition = false;

Open cl_dll/c_prop_vehicle.h

In class C_PropVehicleDriveable replace

	virtual bool IsPredicted() const { return false; }

with

	virtual bool IsPredicted() const { return true; }

Vehicle Camera affecting other players

A simple fix is to make sure the vehicles view changes only affect the local player.

Open cl_dll/c_prop_vehicle.cpp
(Note: As Of 7/05/2009 Using the Orange Box Source SDK build this section is in file vehicle_viewblend_shared.cpp -- line 291 of function "void SharedVehicleViewSmoothing". I recommend you do not make these changes, it causes compile errors, simply make the edits in the next step (SharedVehicleViewSmoothing function in c_prop_vehicle.cpp) --Digi & tymaxbeta)

Find void VehicleViewSmoothing

Replace

	if ( !bExitAnimOn )
	{
		Vector localEyeOrigin;
		QAngle localEyeAngles;

		pData->pVehicle->GetAttachmentLocal( eyeAttachmentIndex, localEyeOrigin, localEyeAngles );
  		engine->SetViewAngles( localEyeAngles );
	}

with

	if ( pPlayer->IsLocalPlayer() )
	{
		if ( !bExitAnimOn )
		{
			Vector localEyeOrigin;
			QAngle localEyeAngles;

			pData->pVehicle->GetAttachmentLocal( eyeAttachmentIndex, localEyeOrigin, localEyeAngles );
  			engine->SetViewAngles( localEyeAngles );
		}
	}

Find C_PropVehicleDriveable::GetVehicleViewPosition

Replace

	VehicleViewSmoothing( m_hPlayer, pAbsOrigin, pAbsAngles, m_bEnterAnimOn, m_bExitAnimOn, &m_vecEyeExitEndpoint, &m_ViewSmoothingData, &m_flFOV );

with

	if( m_hPlayer->IsLocalPlayer() )
	{
		VehicleViewSmoothing( m_hPlayer, pAbsOrigin, pAbsAngles, m_bEnterAnimOn, m_bExitAnimOn, &m_vecEyeExitEndpoint, &m_ViewSmoothingData, &m_flFOV );
	}

For Orange Box:

Replace

	SharedVehicleViewSmoothing( m_hPlayer, pAbsOrigin, pAbsAngles, m_bEnterAnimOn, m_bExitAnimOn, m_vecEyeExitEndpoint, &m_ViewSmoothingData, pFOV );

with

	if( m_hPlayer->IsLocalPlayer() )
	{
		SharedVehicleViewSmoothing( m_hPlayer, pAbsOrigin, pAbsAngles, m_bEnterAnimOn, m_bExitAnimOn, m_vecEyeExitEndpoint, &m_ViewSmoothingData, pFOV );
	}

Programming new vehicle camera

It's possible to program a new vehicle camera loosely based around the point_viewcontrol entity that fixes these issues. It's fully functional but is still being developed I have a detailed tutorial on how I created it along with a test video of it in action:

HL2DM Vehicle Fix

Icon-broom.png
This article or section needs to be cleaned up to conform to a higher standard of quality.
For help, see the VDC Editing Help and Wikipedia cleanup process. Also, remember to check for any notes left by the tagger at this article's talk page.

HL2DM Vehicle Prediction (Partial-Fix) After many days of research and work, I have: A working predicted vehicle! O.k first things first:

Step 1
Make a mod for HL2MP.

Step 2
Build the code so you don't need to wait a long time once you input the new code to find errors.

Step 3
Next, follow this tutorial:

Step 4
Compile and fix any errors. (Right now your vehicles are predicted BUT the camera does not work, so now we are going to fix this )

Step 5
Open hammer using your mod and create a prop_vehicle_jeep or airboat. If you use the jeep make sure you assign the "buggy" model to it or else its just a red cube O.o. Next name the vehicle.

Step 6
Make a point_viewcontrol and move it to where you would like the camera to be when your are in the vehicle. Name it, and parent it to the vehicle. (Do NOT assign a "entity to look at" or else it will not work). Next set the flags "Infinate hold time" and "Interruptable by player" and un-check all the others.

Step 7
Next go back to the vehicle and open the "output" tab. Create a new output and set it as the following:

My output named: PlayerOn Target entity: "camera name" Via this input: enable

Create another and make it:

My output named: PlayerOff Target entity: "camera name" Via this input: disable

  • Optional*

Group the vehicle and camera and move then to the center of grids, then make into a prefab so you can spawn them easily

You now have a working vehicle to use in MP! For multiple vehicles in a level you need to make the names different such as add numbers to the names. I hope this will help you in the future who like me ran into this problem while making a mod. I'm sure if other coders helped make a code for a built in camera this would be very helpful!

See Also