Download

Hello can i get some help with math?

Hello am very new to UE 4 and was hoping for some help on a math problem.


	
    FVector FloorBoxSize = GetWantedBoxSize(); // ..

    FVector BoxLocationWithOffset = GetActorLocation();
    BoxLocationWithOffset.Z -= BoxSize.Z; // Puts the box at desierd height.
    FVecotr End = ?; // Help is needed here.
    ...
    // How can i use this as i do OverlapMulti ?
    GetWorld()->SweepMulti(CurrentOverlapsHits, BoxLocationWithOffset, End/* ? */, FQuat::Identity, FCollisionShape::MakeBox(FloorBoxSize), Params, ObjParams); // Gets the data needed but can`t get it at wanted location and size..
     
// This was very simple way is it not the same this SweepMulti() ?
    GetWorld()->OverlapMulti(CurrentOverlaps, BoxLocationWithOffset, FQuat::Identity, ECollisionChannel::ECC_GameTraceChannel3, FCollisionShape::MakeBox(FloorBoxSize), Params); // Right where i need it to be but don`t return the needed data.


Problem is that i can`t find out how to calculate the correct End location.
I want the sweep/ trace to start and be the same size as FloorBoxSize.

Alice

What is the info you are wanting that overlap is not providing? Cause it really does sound like you want an overlap.

If the proper overlap function cannot be found, you could just sweep for a very small distance!

Below I use more variables than really necessary to make the Vector math equation clear.



//Just move 0.01 in random direction, you really just want a point test (overlap) though. 
//Make smaller than 0.01 if required for accuracy or game scale.
FVector **Distance** = 0.01;
FVector **Dir** = FMath::VRand(); 

FVector **Start** = BoxLocationWithOffset;  //renamed for clarity of calculating End

FVector End = Start + Dir * Distance;


Have you looked in World.h for an overlap function that returns the info you want?

Is your issue that you need the Hit Normals?

Here’s the definition of the OverlapResult that the Overlap multi is returning



/** Structure containing information about one hit of an overlap test */
USTRUCT()
struct ENGINE_API FOverlapResult
{
	GENERATED_USTRUCT_BODY()

	/** Actor that the check hit. */
	UPROPERTY()
	TWeakObjectPtr<class AActor> Actor;

	/** PrimitiveComponent that the check hit. */
	UPROPERTY()
	TWeakObjectPtr<class UPrimitiveComponent> Component;

	/** This is the index of the overlapping item. 
		For DestructibleComponents, this is the ChunkInfo index. 
		For SkeletalMeshComponents this is the Body index or INDEX_NONE for single body */
	int32 ItemIndex;

	/** Utility to return the Actor that owns the Component that was hit */
	AActor* GetActor() const;

	/** Utility to return the Component that was hit */
	UPrimitiveComponent* GetComponent() const;

	/** Indicates if this hit was requesting a block - if false, was requesting a touch instead */
	UPROPERTY()
	uint32 bBlockingHit:1;

	FOverlapResult()
	{
		FMemory::Memzero(this, sizeof(FOverlapResult));
	}
};



Rama

The info i need is int32 FHitResult::Item (Extra data about item that was hit (hit primitive specific).)

I was using the Overlapp version but FOverlapResult don`t have that.
I discoverd that int32 ItemIndex in FOverlapResult did not give me the Instance Index of the mesh.
For the instanced static mesh component, they are in.

But your math is like magic works perfectly. :slight_smile:
Thank you so much.