Example #1
0
void Player::TickLocal( float dt )
{
	float3 oldposition = transform.GetTranslation();

	// Get position update from physics engine
	float3 p = m_charController->GetPosition();
	//m_collider->transform.SetTranslation( p );
	transform.SetTranslation( p + float3( 0, COLLIDER_OFFSET, 0 ) );

	// Read mouse input and rotate
	if( Input::instance->ry != 0 || Input::instance->rx != 0 )
	{
		m_pitch += ( Input::instance->rx * ( PI / 180.f ) * dt * 0.1f );
		m_yaw += Input::instance->ry * dt *  0.1f;
		Transform transf;
		transf.Rotate( float3( -GetRotYaw(), 0, 0.f ) );
		transf.AxisRotate( float3( 0, 1, 0 ), GetRotation() );
	//	transf.SetTranslation( p );
		Camera::s_mainCamera->transform = transf;
		//Camera::s_mainCamera->transform.Rotate( float3( -dt * Input::instance->ry * 0.1f, 0, 0 ) );
		//Camera::s_mainCamera->transform.AxisRotate( float3( 0, 1, 0 ), Input::instance->rx * ( PI / 180 ) * dt * 0.1f );
	}

	transform.Rotate( float3( 0, -m_pitch * ( 180 / PI ), 0 ) );
	m_rotation += m_pitch;
	m_rotYaw += m_yaw;
	m_acceleration = float3( 0, 0, 0 );
	ProcessInput( dt );
	matrix rotation;
	rotation.RotateY( -m_rotation * ( 180 / PI ) );
	m_acceleration = rotation.Transform( m_acceleration );
	m_charController->Move( m_acceleration );
	m_charController->Tick( dt );

	if( Network::Get()->IsConnected() )
	{
		float3 newPos = float3::Lerp(
			transform.GetTranslation() + ( m_netTransform.GetTranslation() - transform.GetTranslation() ) * 0.1f
			, m_netTransform.GetTranslation(), dt * 0.05f );

		m_charController->MoveTo( newPos - float3( 0, COLLIDER_OFFSET, 0 ) );
	}

	float3 vel = transform.GetTranslation() - oldposition;
	if( transform.GetTranslation().y < -7.f && m_state == ALIVE ) Suicide();
	// Set camera //
	Camera::s_mainCamera->transform.SetTranslation( transform.GetTranslation() + float3( 0.f, 2.f, 0.f ) );
}