Exemplo n.º 1
0
void ACharacter::LaunchCharacter(FVector LaunchVelocity, bool bXYOverride, bool bZOverride)
{
	if (CharacterMovement && ((Role == ROLE_Authority) || IsLocallyControlled()))
	{
		FVector FinalVel = LaunchVelocity;
		if (MovementBaseUtility::IsDynamicBase(MovementBase))
		{
			// Is this right? What if we are based on non root component and the root component has a velocity? Will it be lost?
			FinalVel += MovementBase->GetComponentVelocity();
		}

		if (!bXYOverride)
		{
			FinalVel.X += GetVelocity().X;
			FinalVel.Y += GetVelocity().Y;
		}
		if (!bZOverride)
		{
			FinalVel.Z += GetVelocity().Z;
		}

		CharacterMovement->Launch(FinalVel);

		OnLaunched(LaunchVelocity, bXYOverride, bZOverride);
	}
}
Exemplo n.º 2
0
void APlayerCharacter::PlayHitSound()
{
    if ( HitSound && IsLocallyControlled() )
    {
        UGameplayStatics::SpawnSoundAttached(HitSound, Mesh1P);
    }
}
void UGripMotionControllerComponent::TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction)
{
	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

	// Moved this here instead of in the polling function, it was ticking once per frame anyway so no loss of perf
	// It doesn't need to be there and now I can pre-check
	// Also epics implementation in the polling function didn't work anyway as it was based off of playercontroller which is not the owner of this controller
	
	// Cache state from the game thread for use on the render thread
	// No need to check if in game thread here as tick always is
	bHasAuthority = IsLocallyControlled();
	bIsServer = IsServer();

	// Server/remote clients don't set the controller position in VR
	// Don't call positional checks and don't create the late update scene view
	if (bHasAuthority)
	{
		if (!ViewExtension.IsValid() && GEngine)
		{
			TSharedPtr< FViewExtension, ESPMode::ThreadSafe > NewViewExtension(new FViewExtension(this));
			ViewExtension = NewViewExtension;
			GEngine->ViewExtensions.Add(ViewExtension);
		}

		// This is the owning player, now you can get the controller's location and rotation from the correct source
		FVector Position;
		FRotator Orientation;
		bTracked = PollControllerState(Position, Orientation);

		if (bTracked)
		{
			SetRelativeLocationAndRotation(Position, Orientation);
		}

		if (!bTracked && !bUseWithoutTracking)
			return; // Don't update anything including location

		// Don't bother with any of this if not replicating transform
		if (bReplicates && bTracked)
		{
			ReplicatedControllerTransform.Position = Position;
			ReplicatedControllerTransform.Orientation = Orientation;

			if (GetNetMode() == NM_Client)//bReplicateControllerTransform)
			{
				ControllerNetUpdateCount += DeltaTime;
				if (ControllerNetUpdateCount >= (1.0f / ControllerNetUpdateRate))
				{
					ControllerNetUpdateCount = 0.0f;
					Server_SendControllerTransform(ReplicatedControllerTransform);
				}
			}
		}
	}

	// Process the gripped actors
	TickGrip();

}
Exemplo n.º 4
0
void AFireball::BeginPlay()
{
	Super::BeginPlay();

	MovementComponent->SetActive(false);

	MousePressedTime = 0;
	
	FireScale = 1;

	ParticleSystemComponent->SetIsReplicated(true);

	if (GetGameInstance()->GetFirstLocalPlayerController() != NULL) {
		//auto inputManager = UInputEventManager::Get();
		auto pc = Cast<AThirdPersonProjectCharacter>(GetOwner());
		if (pc && pc->IsLocallyControlled()) {
			pc->OnMouseEvent.AddDynamic(this, &AFireball::OnMouseEvent);
		}
	}
}
Exemplo n.º 5
0
// Called every frame
void ABaseCharacter::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

	if (bIsSprinting)
	{
		GetCharacterMovement()->MaxWalkSpeed = SprintSpeed;
		GetCharacterMovement()->MaxFlySpeed = SprintSpeed;
	}
	else
	{
		GetCharacterMovement()->MaxWalkSpeed = OriginalWalkSpeed;
		GetCharacterMovement()->MaxFlySpeed = OriginalWalkSpeed;
	}

	//can aim down sight on third person
	bool CanAdsOnTP = !bAlwaysADS && !IsLocallyControlled();

	if (!CanAdsOnTP)
	{
		ADSBlend = 1.0f; //1 = fully blend into aiming down sight animation
	}

	if (bIsAimingDownSights)
	{
		if (CanAdsOnTP)
			ADSBlend = FMath::FInterpTo(ADSBlend, 1.0f, DeltaTime, ADSBlendInterpSpeed);
		
		Camera->FieldOfView = FMath::FInterpTo(Camera->FieldOfView, ADSCameraFOV, DeltaTime, ADSBlendInterpSpeed);
	}
	else
	{
		if (CanAdsOnTP)
			ADSBlend = FMath::FInterpTo(ADSBlend, 0.0f, DeltaTime, ADSBlendInterpSpeed);
		
		Camera->FieldOfView = FMath::FInterpTo(Camera->FieldOfView, CameraFOV, DeltaTime, ADSBlendInterpSpeed);
	}

}
Exemplo n.º 6
0
bool APawn::ShouldTickIfViewportsOnly() const 
{ 
	return IsLocallyControlled() && Cast<APlayerController>(GetController()); 
}