언리얼엔진3 에서 방향키 입력에 따른 처리과정
Engine 레이어에서 기본적으로 설정된 방향키는 아래와 같다.
[Engine.PlayerInput] ... Bindings=(Name="MoveForward",Command="Axis aBaseY Speed=1.0") ... Bindings=(Name="W",Command="MoveForward")
W 를 누르면 MoveForward 커맨드가 수행되고 MoveForward 커맨드는 Axis aBaseY Speed=1.0 을 수행한다.
엔진에서 Axis 커맨드를 처리하는 부분은 아래와 같다.
... UBOOL UInput::Exec( const TCHAR* Str, FOutputDevice& Ar ) { ... else if ( ParseCommand( &Str, TEXT("AXIS") ) ) { FLOAT* Axis; if ( ParseToken( Str, Temp, ARRAY_COUNT(Temp), 0 ) && (Axis=FindAxisName(Temp)) != NULL ) { ... // Axis 에 적절한 값을 넣어주는 로직 } } ... }
전체적인 흐름은 다음과 같다.
요약하자면 Axis aBaseY Speed=1.0 커맨드는 PlayerInput.aBaseY 변수에 1.0 의 값을 대입한다.
PlayerInput 에 aBaseY 란 변수는 플레이어의 전/후 이동을 책임지는 변수에 대입된다. (예상하겠지만 X 축은 횡이동)
해당 로직은 아래와 같다.
event PlayerInput( float DeltaTime ) { ... aForward += aBaseY; ... }
aForward 를 비롯하여 aTurn, aStrafe, aUp, aLookUp 변수가 플레이어 이동에 관여되어 있다.
PlayerInput 에 aForward 변수는 실제 플레이어의 Acceleration 에 영향을 미친다.
해당 로직은 아래와 같다.
state PlayerWalking { function PlayerMove( float DeltaTime ) { ... GetAxes( Pawn.Rotation, X, Y, Z ); NewAccel = PlayerInput.aForward * X + PlayerInput.aStrafe * Y; ... ProcessMove( DeltaTime, NewAccel, DoubleClickMove, OldRotation - Rotation ); ... } }