Example #1
0
ABrainInteractiveObject* ABrainCharacter::CheckForInteractiveObjects()
{
	FCollisionQueryParams traceParams = FCollisionQueryParams(FName(TEXT("Trace")), true, this);
	
	traceParams.bTraceComplex = true;
	traceParams.bTraceAsyncScene = true;
	traceParams.bReturnPhysicalMaterial = true;
	
	FHitResult hit(ForceInit);

	UWorld* world = GetWorld();

	FVector startLocation = GetActorLocation() + FVector(0, 0, 64); // tweak pour prendre en compte la position de la camera.
	FVector endLocation = startLocation + (GetActorRotation().Vector() * _maxDistanceInteraction);

	world->SweepSingleByChannel(hit, startLocation, endLocation, FQuat::Identity, INTERACTIVE_OBJECT, FCollisionShape::MakeSphere(12.0f), traceParams);
	
	return Cast<ABrainInteractiveObject>(hit.GetActor());
}
UPrimitiveComponent* UPhysicsSpringComponent::GetSpringCollision(const FVector& Start, const FVector& End, float& Time) const
{
	UWorld* World = GetWorld();
	AActor* IgnoreActor = bIgnoreSelf ? GetOwner() : nullptr;

	static FName NAME_Spring = FName(TEXT("SpringComponent"));
	FCollisionQueryParams QueryParams(NAME_Spring, true, IgnoreActor);
	FHitResult Hit;

	UPrimitiveComponent* CollidedComponent = nullptr;
	
	const FVector Delta = End - Start;
	const float DeltaSizeSqr = Delta.SizeSquared();
	if (DeltaSizeSqr > FMath::Square(SMALL_NUMBER))
	{
		if (bool bBlockingHit = World->SweepSingleByChannel(Hit, Start, End, FQuat::Identity, SpringChannel, FCollisionShape::MakeSphere(SpringRadius), QueryParams))
		{
			CollidedComponent = Hit.GetComponent();
			Time = CollidedComponent ? Hit.Time : 1.f;
		}
	}

	return CollidedComponent;
}