First Person Ragdolls: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(Undo revision 175597 by Slam12f (talk))
No edit summary
Line 1: Line 1:
{{otherlang2
{{otherlang2
|es=Смерть от первого лица:es
|es=First_Person_Ragdolls:es
|de=Ragdolls от первого лица:de
|de=First_Person_Ragdolls:de
}}
}}


[[Image:Dm resistance0008.jpg|right|250px|thumb|Смерть от первого лица в игре HL2DM]]
[[Image:Dm resistance0008.jpg|right|250px|thumb|Ragdoll death from first person perspective in HL2DM]]


В большинстве многопользовательских модов Source, после смерти вид от первого лица переключается на третье. Эти простые изменения кода, дадут возможность игроку видеть смерть от первого лица.
In most Source multi-player mods, when a player dies the view switches from first to third person perspective. This following simple code change allows you to give the player an option of seeing things from the ragdolls perspective, in short letting it see the world through the ragdoll's own eyes.


== Необходимые условия ==
== Pre-requisites ==


Для работы этого кода, ваша модель должна иметь attachment называемым <code>eyes</code> куда и будет установлена камера. По стандарту все human characters модели (человеческие модели) имеют этот attachment, но если на вашей модели его нет, то добавьте его через [[QC команды в |QC File]] и [[HLMV]].
For the code to work, your player model needs an attachment called <code>eyes</code> which represents where on the ragdoll the players view will come from. In the case of the default HL2 human characters they already have one but if your player model doesn't you can add it in via the [[QC Commands|QC File]] and [[HLMV]].


== Изменения Кода==
== Code changes ==


Код предназначен для '''HL2DM''' но должен работать с другими модами, при небольшом изменение кода.
The following is for mods based on '''HL2DM''' but should work with others with some minor editing.


=== c_hl2mp_player.cpp ===
=== c_hl2mp_player.cpp ===


Т.к. этот код относиться к клиенту, делаем изменения в файле <code>client\hl2mp\c_hl2mp_player.cpp</code>.
As this code is clientside, we're making edits to the file <code>client\hl2mp\c_hl2mp_player.cpp</code>.


Первым делом добавим консольную команду включения и отключения смерти от первого лица. Это следует разместить в верхнюю часть файла, с аналогичными консольными командами:
The first part is to add a console command to enable or disable first person ragdolls. This should be placed at the top of the file along with the other console commands:
<pre>
<pre>
static ConVar cl_fp_ragdoll ( "cl_fp_ragdoll", "1", FCVAR_ARCHIVE, "Allow first person ragdolls" );
static ConVar cl_fp_ragdoll ( "cl_fp_ragdoll", "1", FCVAR_ARCHIVE, "Allow first person ragdolls" );
Line 26: Line 26:
</pre>
</pre>


Следующий шаг, это редактирование функции<code>CalcView</code>. Эта функция проверяет, если игрок мертв. Если да, то переключаемся на вид от третьего лица. Добавляем наш код, вид от первого лица:
The next step is to edit the <code>CalcView</code> function. This function checks to see if the player is dead and if so, switches to third person view. In this case we're adding the extra code for first person ragdolls:


<pre>
<pre>
Line 47: Line 47:
if ( cl_fp_ragdoll_auto.GetBool() )
if ( cl_fp_ragdoll_auto.GetBool() )
{
{
// DM: отключаем вид от первого лица, когда камера близко к поверхности чего либо (Slam12f)
// DM: Don't use first person view when we are very close to something
trace_t tr;
trace_t tr;
UTIL_TraceLine( eyeOrigin, eyeOrigin + ( vForward * 10000 ), MASK_ALL, pRagdoll, COLLISION_GROUP_NONE, &tr );
UTIL_TraceLine( eyeOrigin, eyeOrigin + ( vForward * 10000 ), MASK_ALL, pRagdoll, COLLISION_GROUP_NONE, &tr );
Line 91: Line 91:
</pre>
</pre>


Когда cl_fp_ragdoll_auto включён, код автоматически включает вид от третьего лица, когда камера находиться вблизи какой-либо поверхности.
When cl_fp_ragdoll_auto is also on, the code automatically switches to third person when there isn't much to see.


== Незначительные проблемы ==
== Minor issues ==
Иногда, можно заметить, что вы можете видеть сквозь стены пол и т.п. Это происходит потому-что камера находится слишком близко к поверхности.


Часто это встречается в стандартных моделях HL2, голова которых слишком свободна в движение. Это можно устранить путём редактирования "веса" физической модели (1) и ограничениях движения головы (2), чтобы падение выглядело более естественно.  Также можно сделать головную часть физической модели немного больше, около носа и бровей. Это часто помогает остановить attachment от проникновения в поверхность.
Occasionally you may find that when the players head is close to a surface it clips through allowing you to see through to the other side. This is often because the eye origin is extremely close or even through the surface itself.


*1 - Скорее всего речь идёт о весе кости.
Often this can be tracked down to the default HL2 physics model which is very loose and in the case of the head, quite small. You may find that you can reduce this happening by editing the physics model's weights and constraints so that the ragdoll falls in a more natural way. Also making the head part of the physics model a little larger near the nose and brow often helps in stopping the eye attachment from penetrating a surface.
*2 - Имеется ввиду уменьшение наклона кости.


Перевод: --[[User:Slam12f|Slam12f]] 21:18, 9 May 2013 (PDT)


[[Категория:Программирование]]
[[Category:Programming]]

Revision as of 04:38, 10 May 2013

Template:Otherlang2

Ragdoll death from first person perspective in HL2DM

In most Source multi-player mods, when a player dies the view switches from first to third person perspective. This following simple code change allows you to give the player an option of seeing things from the ragdolls perspective, in short letting it see the world through the ragdoll's own eyes.

Pre-requisites

For the code to work, your player model needs an attachment called eyes which represents where on the ragdoll the players view will come from. In the case of the default HL2 human characters they already have one but if your player model doesn't you can add it in via the QC File and HLMV.

Code changes

The following is for mods based on HL2DM but should work with others with some minor editing.

c_hl2mp_player.cpp

As this code is clientside, we're making edits to the file client\hl2mp\c_hl2mp_player.cpp.

The first part is to add a console command to enable or disable first person ragdolls. This should be placed at the top of the file along with the other console commands:

static ConVar cl_fp_ragdoll ( "cl_fp_ragdoll", "1", FCVAR_ARCHIVE, "Allow first person ragdolls" );
static ConVar cl_fp_ragdoll_auto ( "cl_fp_ragdoll_auto", "1", FCVAR_ARCHIVE, "Autoswitch to ragdoll thirdperson-view when necessary" );

The next step is to edit the CalcView function. This function checks to see if the player is dead and if so, switches to third person view. In this case we're adding the extra code for first person ragdolls:

void C_HL2MP_Player::CalcView( Vector &eyeOrigin, QAngle &eyeAngles, float &zNear, float &zFar, float &fov )
{
	// if we're dead, we want to deal with first or third person ragdolls.
	if ( m_lifeState != LIFE_ALIVE && !IsObserver() )
	{
		// First person ragdolls
		if ( cl_fp_ragdoll.GetBool() && m_hRagdoll.Get() )
		{
			// pointer to the ragdoll
			C_HL2MPRagdoll *pRagdoll = (C_HL2MPRagdoll*)m_hRagdoll.Get();

			// gets its origin and angles
			pRagdoll->GetAttachment( pRagdoll->LookupAttachment( "eyes" ), eyeOrigin, eyeAngles );
			Vector vForward; 
			AngleVectors( eyeAngles, &vForward );

			if ( cl_fp_ragdoll_auto.GetBool() )
			{
				// DM: Don't use first person view when we are very close to something
				trace_t tr;
				UTIL_TraceLine( eyeOrigin, eyeOrigin + ( vForward * 10000 ), MASK_ALL, pRagdoll, COLLISION_GROUP_NONE, &tr );

				if ( (!(tr.fraction < 1) || (tr.endpos.DistTo(eyeOrigin) > 25)) )
					return;
			}
			else
				return;
		}

		eyeOrigin = vec3_origin;
		eyeAngles = vec3_angle;

		Vector origin = EyePosition();
		IRagdoll *pRagdoll = GetRepresentativeRagdoll();
		if ( pRagdoll )
		{
			origin = pRagdoll->GetRagdollOrigin();
			origin.z += VEC_DEAD_VIEWHEIGHT.z; // look over ragdoll, not through
		}
		BaseClass::CalcView( eyeOrigin, eyeAngles, zNear, zFar, fov );
		eyeOrigin = origin;
		Vector vForward; 
		AngleVectors( eyeAngles, &vForward );
		VectorNormalize( vForward );
		VectorMA( origin, -CHASE_CAM_DISTANCE, vForward, eyeOrigin );
		Vector WALL_MIN( -WALL_OFFSET, -WALL_OFFSET, -WALL_OFFSET );
		Vector WALL_MAX( WALL_OFFSET, WALL_OFFSET, WALL_OFFSET );
		trace_t trace; // clip against world
		// HACK don't recompute positions while doing RayTrace
		C_BaseEntity::EnableAbsRecomputations( false );
		UTIL_TraceHull( origin, eyeOrigin, WALL_MIN, WALL_MAX, MASK_SOLID_BRUSHONLY, this, COLLISION_GROUP_NONE, &trace );
		C_BaseEntity::EnableAbsRecomputations( true );
		if (trace.fraction < 1.0)
		{
			eyeOrigin = trace.endpos;
		}
		return;
	}
	BaseClass::CalcView( eyeOrigin, eyeAngles, zNear, zFar, fov );
}

When cl_fp_ragdoll_auto is also on, the code automatically switches to third person when there isn't much to see.

Minor issues

Occasionally you may find that when the players head is close to a surface it clips through allowing you to see through to the other side. This is often because the eye origin is extremely close or even through the surface itself.

Often this can be tracked down to the default HL2 physics model which is very loose and in the case of the head, quite small. You may find that you can reduce this happening by editing the physics model's weights and constraints so that the ragdoll falls in a more natural way. Also making the head part of the physics model a little larger near the nose and brow often helps in stopping the eye attachment from penetrating a surface.