void UActorDetectorComponent::RunDetection()
{
	TArray<AActor*> OverlappingActors;
	GetOwner()->GetOverlappingActors(OverlappingActors);

	if (OverlappingActors.Num() > 0)
	{
		for (size_t i = 0; i < OverlappingActors.Num(); i++)
		{
			if (OverlappingActors[i]->ActorHasTag(TagToDetect))
			{
				// Get directions
				FVector OwnerDirection = GetOwner()->GetActorForwardVector();
				FVector ActorDirection = OverlappingActors[i]->GetActorLocation() - GetOwner()->GetActorLocation();

				// Normalize vectors
				OwnerDirection.Normalize();
				ActorDirection.Normalize();

				// Calculate angle
				float AngleFromForward = FMath::RadiansToDegrees(acosf(FVector::DotProduct(OwnerDirection, ActorDirection)));
				if (AngleFromForward < MaxAngleDetection)
				{
					//UE_LOG(LogTemp, Warning, TEXT("Lanzo Broadcast"));
					ActorDetected.Broadcast(OverlappingActors[i]);
				}
				//UE_LOG(LogTemp, Warning, TEXT("Tiene tag Name: %s y angulo %f, max %f"), *(OverlappingActors[i]->GetName()), AngleFromForward, MaxAngleDetection);
			}
		}
	}
}
bool UAbilitySystemBlueprintLibrary::GetGameplayCueDirection(AActor* TargetActor, FGameplayCueParameters Parameters, FVector& Direction)
{
	if (FGameplayEffectContext* Ctx = Parameters.EffectContext.Get())
	{
		if (Ctx->GetHitResult())
		{
			// Most projectiles and melee attacks will use this
			Direction = (-1.f * Ctx->GetHitResult()->Normal);
			return true;
		}
		else if (TargetActor && Ctx->HasOrigin())
		{
			// Fallback to trying to use the target location and the origin of the effect
			FVector NewVec = (TargetActor->GetActorLocation() - Ctx->GetOrigin());
			NewVec.Normalize();
			Direction = NewVec;
			return true;
		}
		else if (TargetActor && Ctx->GetEffectCauser())
		{
			// Finally, try to use the direction between the causer of the effect and the target of the effect
			FVector NewVec = (TargetActor->GetActorLocation() - Ctx->GetEffectCauser()->GetActorLocation());
			NewVec.Normalize();
			Direction = NewVec;
			return true;
		}
	}

	Direction = FVector::ZeroVector;
	return false;
}
Esempio n. 3
0
void ABounceBlock::OnHit(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
{
	//衝突された場合の判定
	UE_LOG(LogTemp, Log, TEXT("On Hit Call!"));

	//横方向に限定して弾き返す
	float speed = NormalImpulse.Size();
	NormalImpulse.Z = 0;

	//ベロシティを反射方向に導く
	FVector velocity = OtherComp->GetComponentVelocity();
	float power = velocity.Size();
	if (power > 0.0f){
		NormalImpulse.Normalize();
		NormalImpulse = velocity + 2 * (-velocity | NormalImpulse) * NormalImpulse;

		power = NormalImpulse.Size();
		NormalImpulse.Z = 0;
		NormalImpulse.Normalize();

		NormalImpulse *= power;

		OtherComp->SetPhysicsLinearVelocity(NormalImpulse);
	}

	//トルクを0にしてみる
	OtherComp->SetPhysicsAngularVelocity(FVector(0, 0, 0));

	//弾き返す!!
	//OtherComp->AddImpulseAtLocation(NormalImpulse * 2.0f, Hit.Location);

}
void AFlySkillActor::Injury_Implementation()
{
	AAONGameState* ags = Cast<AAONGameState>(UGameplayStatics::GetGameState(GetWorld()));
	for (AHeroCharacter* hero : AttackCollision)
	{
		// 如果不同隊才造成傷害
		if (hero && hero->TeamId != this->TeamId)
		{
			// 物傷
			if (PhysicalDamage > 0)
			{
				float Injury = ags->ArmorConvertToInjuryPersent(hero->CurrentArmor);
				float Damage = PhysicalDamage * Injury;
				hero->CurrentHP -= Damage;

				// 顯示傷害文字
				ADamageEffect* TempDamageText = GetWorld()->SpawnActor<ADamageEffect>(AHeroCharacter::ShowDamageEffect);
				if (TempDamageText)
				{
					FVector pos = hero->GetActorLocation();
					pos.X += 10;
					TempDamageText->OriginPosition = pos;
					TempDamageText->SetString(FString::FromInt((int32)Damage));
					FVector scaleSize(TempDamageText->ScaleSize, TempDamageText->ScaleSize, TempDamageText->ScaleSize);
					TempDamageText->SetActorScale3D(scaleSize);
					FVector dir = hero->GetActorLocation() - GetActorLocation();
					dir.Normalize();
					TempDamageText->FlyDirection = dir;
				}
			}
			// 法傷
			if (MagicDamage > 0)
			{
				float Damage = MagicDamage * (1 - hero->CurrentMagicInjured);
				hero->CurrentHP -= Damage;

				// 顯示傷害文字
				ADamageEffect* TempDamageText = GetWorld()->SpawnActor<ADamageEffect>(AHeroCharacter::ShowDamageEffect);
				if (TempDamageText)
				{
					FVector pos = hero->GetActorLocation();
					pos.X += 10;
					TempDamageText->OriginPosition = pos;
					TempDamageText->SetString(FString::FromInt((int32)Damage));
					FVector scaleSize(TempDamageText->ScaleSize, TempDamageText->ScaleSize, TempDamageText->ScaleSize);
					TempDamageText->SetActorScale3D(scaleSize);
					FVector dir = hero->GetActorLocation() - GetActorLocation();
					dir.Normalize();
					TempDamageText->FlyDirection = dir;
				}
			}
			hero->BuffQueue.Append(Buffs);
		}
	}
	AttackCollision.Empty();
}
FRotator UKismetMathLibrary::MakeRotationFromAxes(FVector Forward, FVector Right, FVector Up)
{
	Forward.Normalize();
	Right.Normalize();
	Up.Normalize();

	FMatrix RotMatrix(Forward, Right, Up, FVector::ZeroVector);

	return RotMatrix.Rotator();
}
Esempio n. 6
0
/** Utility for calculating drag direction when you click on this widget. */
void HWidgetUtilProxy::CalcVectors(FSceneView* SceneView, const FViewportClick& Click, FVector& LocalManDir, FVector& WorldManDir, float& DragDirX, float& DragDirY)
{
	if(Axis == EAxisList::X)
	{
		WorldManDir = WidgetMatrix.GetScaledAxis( EAxis::X );
		LocalManDir = FVector(1,0,0);
	}
	else if(Axis == EAxisList::Y)
	{
		WorldManDir = WidgetMatrix.GetScaledAxis( EAxis::Y );
		LocalManDir = FVector(0,1,0);
	}
	else
	{
		WorldManDir = WidgetMatrix.GetScaledAxis( EAxis::Z );
		LocalManDir = FVector(0,0,1);
	}

	FVector WorldDragDir = WorldManDir;

	if(Mode == WMM_Rotate)
	{
		if( FMath::Abs(Click.GetDirection() | WorldManDir) > KINDA_SMALL_NUMBER ) // If click direction and circle plane are parallel.. can't resolve.
		{
			// First, find actual position we clicking on the circle in world space.
			const FVector ClickPosition = FMath::LinePlaneIntersection(	Click.GetOrigin(),
																	Click.GetOrigin() + Click.GetDirection(),
																	WidgetMatrix.GetOrigin(),
																	WorldManDir );

			// Then find Radial direction vector (from center to widget to clicked position).
			FVector RadialDir = ( ClickPosition - WidgetMatrix.GetOrigin() );
			RadialDir.Normalize();

			// Then tangent in plane is just the cross product. Should always be unit length again because RadialDir and WorlManDir should be orthogonal.
			WorldDragDir = RadialDir ^ WorldManDir;
		}
	}

	// Transform world-space drag dir to screen space.
	FVector ScreenDir = SceneView->ViewMatrices.ViewMatrix.TransformVector(WorldDragDir);
	ScreenDir.Z = 0.0f;

	if( ScreenDir.IsZero() )
	{
		DragDirX = 0.0f;
		DragDirY = 0.0f;
	}
	else
	{
		ScreenDir.Normalize();
		DragDirX = ScreenDir.X;
		DragDirY = ScreenDir.Y;
	}
}
Esempio n. 7
0
// Called every frame
void APawnWithCamera::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

	//Rotate our actor's yaw, which will turn our camera because we're attached to it
	{
		FRotator NewRotation = OurCameraBase->GetComponentRotation();
		NewRotation.Yaw += -CameraInput.X;
		OurCameraBase->SetWorldRotation(NewRotation);
	}

	//Rotate our camera's pitch, but limit it so we're always looking downward
	{
		FRotator NewRotation = OurCameraBase->GetComponentRotation();
		NewRotation.Pitch = FMath::Clamp(NewRotation.Pitch - CameraInput.Y, -80.0f, 80.0f);
		OurCameraBase->SetWorldRotation(NewRotation);
	}

	//Handle movement based on our "MoveX" and "MoveY" axes
	{
		if (!MovementInput.IsZero())
		{
			//Scale our movement input axis values by 100 units per second
			MovementInput = MovementInput.SafeNormal() * 100.0f;
			FVector NewLocation = GetActorLocation();
			NewLocation += GetActorForwardVector() * MovementInput.X * DeltaTime;
			NewLocation += GetActorRightVector() * MovementInput.Y * DeltaTime;
			SetActorLocation(NewLocation);
		}
	}




	FVector LeftEyePosition = LeftEyePos->GetComponentLocation() - OurCamera->GetComponentLocation();
	LeftEyePosition.Normalize();

	FVector RightEyePosition = RightEyePos->GetComponentLocation() - OurCamera->GetComponentLocation();
	RightEyePosition.Normalize();

	FVector4 LeftEyeWeight;
	FVector4 RightEyeWeight;

	for (int i = 0; i < 4; i++)
	{
		LeftEyeWeight[i] = FVector::DotProduct((LeftEyePosition - FishEyePos[i]), dir[i]) / length[i];
		RightEyeWeight[i] = FVector::DotProduct((RightEyePosition - FishEyePos[i]), dir[i]) / length[i];
	}

	RV_MatInst->SetVectorParameterValue(FName("LeftEyePos"), LeftEyePosition);
	RV_MatInst->SetVectorParameterValue(FName("RightEyePos"), RightEyePosition);
	RV_MatInst->SetVectorParameterValue(FName("RightWeight"), LeftEyePosition);
	RV_MatInst->SetVectorParameterValue(FName("LeftWeight"), RightEyePosition);
}
FVector UFlareSpacecraftNavigationSystem::GetAngularVelocityToAlignAxis(FVector LocalShipAxis, FVector TargetAxis, FVector TargetAngularVelocity, float DeltaSeconds) const
{
	TArray<UActorComponent*> Engines = Spacecraft->GetComponentsByClass(UFlareEngine::StaticClass());

	FVector AngularVelocity = Spacecraft->Airframe->GetPhysicsAngularVelocity();
	FVector WorldShipAxis = Spacecraft->Airframe->GetComponentToWorld().GetRotation().RotateVector(LocalShipAxis);

	WorldShipAxis.Normalize();
	TargetAxis.Normalize();

	FVector RotationDirection = FVector::CrossProduct(WorldShipAxis, TargetAxis);
	RotationDirection.Normalize();
	float Dot = FVector::DotProduct(WorldShipAxis, TargetAxis);
	float angle = FMath::RadiansToDegrees(FMath::Acos(Dot));

	FVector DeltaVelocity = TargetAngularVelocity - AngularVelocity;
	FVector DeltaVelocityAxis = DeltaVelocity;
	DeltaVelocityAxis.Normalize();

	float TimeToFinalVelocity;

	if (FMath::IsNearlyZero(DeltaVelocity.SizeSquared()))
	{
		TimeToFinalVelocity = 0;
	}
	else {
		FVector SimpleAcceleration = DeltaVelocityAxis * GetAngularAccelerationRate();
		// Scale with damages
		float DamageRatio = GetTotalMaxTorqueInAxis(Engines, DeltaVelocityAxis, true) / GetTotalMaxTorqueInAxis(Engines, DeltaVelocityAxis, false);
		FVector DamagedSimpleAcceleration = SimpleAcceleration * DamageRatio;

		FVector Acceleration = DamagedSimpleAcceleration;
		float AccelerationInAngleAxis =  FMath::Abs(FVector::DotProduct(DamagedSimpleAcceleration, RotationDirection));

		TimeToFinalVelocity = (DeltaVelocity.Size() / AccelerationInAngleAxis);
	}

	float AngleToStop = (DeltaVelocity.Size() / 2) * (FMath::Max(TimeToFinalVelocity,DeltaSeconds));

	FVector RelativeResultSpeed;

	if (AngleToStop > angle) {
		RelativeResultSpeed = TargetAngularVelocity;
	}
	else
	{
		float MaxPreciseSpeed = FMath::Min((angle - AngleToStop) / (DeltaSeconds * 0.75f), GetAngularMaxVelocity());

		RelativeResultSpeed = RotationDirection;
		RelativeResultSpeed *= MaxPreciseSpeed;
	}

	return RelativeResultSpeed;
}
void ACinemotusPlayerController::HandleMovementAbs(float DeltaTime, bool useHydraMotion = false)
{
	APawn* pawn = GetPawn();
	if (!pawn)
	{
		return;
	}

	

	//check velocities
	FVector velocity = useHydraMotion ? HydraLatestData->controllers[CAM_HAND].velocity : FVector::ZeroVector;
	FVector velRel = FVector(velocity);
	FRotationMatrix mat(GetControlRotation());
	float scalar = 2.5;
	if (useHydraMotion)
	{
		FRotationMatrix cMat(HydraLatestData->controllers[CAM_HAND].rotation);
		velRel.X = FVector::DotProduct(cMat.GetScaledAxis(EAxis::X), velocity);
		velRel.Y = FVector::DotProduct(cMat.GetScaledAxis(EAxis::Y), velocity);
		velRel.Z = FVector::DotProduct(cMat.GetScaledAxis(EAxis::Z), velocity); //take motion and make relative to the orientation of the controller
	}
	//velocity.X*DeltaTime * scaleCmToMetres*fSpeedMulitplier +

	pawn->AddMovementInput(mat.GetScaledAxis(EAxis::X), velRel.X*DeltaTime * scalar*fSpeedMulitplier + vXYandCrane.X);
	pawn->AddMovementInput(mat.GetScaledAxis(EAxis::Y), velRel.Y*DeltaTime * scalar*fSpeedMulitplier + vXYandCrane.Y);
	pawn->AddMovementInput(mat.GetScaledAxis(EAxis::Z), velRel.Z*DeltaTime * scalar*fSpeedMulitplier);
	pawn->AddMovementInput(FVector::UpVector, vXYandCrane.Z);


	//Add Movement input for offhand

	FVector xPlanar = mat.GetScaledAxis(EAxis::X);
	xPlanar.Z = 0;
	bool didNorm = xPlanar.Normalize();
	if (!didNorm)
	{ 
		xPlanar.X = 1.0; xPlanar.Normalize(); }
	pawn->AddMovementInput(xPlanar, offHandPlanarMovement.X);


	FVector yPlanar = mat.GetScaledAxis(EAxis::Y);
	yPlanar.Z = 0;
	didNorm = yPlanar.Normalize();
	if (!didNorm) { yPlanar.Y = 1.0; yPlanar.Normalize(); }
	pawn->AddMovementInput(yPlanar, offHandPlanarMovement.Y);



}
Esempio n. 10
0
void ABaseWeapon::Instant_Fire()
{
	const int32 RandomSeed = FMath::Rand();
	FRandomStream WeaponRandomStream(RandomSeed);
	const float CurrentSpread = WeaponConfig.WeaponSpread;
	const float SpreadCone = FMath::DegreesToRadians(WeaponConfig.WeaponSpread * 0.5);
	const FVector AimDir = MyPawn->GetActorForwardVector();
	const FVector StartTrace = MyPawn->GetActorLocation();
	const FVector ShootDir = WeaponRandomStream.VRandCone(AimDir, SpreadCone, SpreadCone);
	FVector EndTrace;

	if (Target)
	{
		FVector TargetDir = (MyPawn->GetActorLocation() - Target->GetActorLocation());
		TargetDir.Normalize();
		FVector ShootDir2 = WeaponRandomStream.VRandCone(-TargetDir, SpreadCone, SpreadCone);
		EndTrace = StartTrace + ShootDir2 * WeaponConfig.WeaponRange;
	}
	else
	{
		EndTrace = StartTrace + ShootDir * WeaponConfig.WeaponRange;
	}

	const FHitResult Impact = WeaponTrace(StartTrace, EndTrace);
	SpawnParticle(EndTrace);
	HitActor = Cast<AActor>(Impact.GetActor());

	//DrawDebugLine(GetWorld(), StartTrace, EndTrace, FColor::Red, false, 1.0f);

	if (HitActor)
	{
		Server_DealDamage(Impact, ShootDir, WeaponConfig);
	}
}
void UAnimGraphNode_BoneDrivenController::Draw(FPrimitiveDrawInterface* PDI, USkeletalMeshComponent* SkelMeshComp) const
{	
	static const float ArrowHeadWidth = 5.0f;
	static const float ArrowHeadHeight = 8.0f;

	int32 SourceIdx = SkelMeshComp->GetBoneIndex(Node.SourceBone.BoneName);
	int32 TargetIdx = SkelMeshComp->GetBoneIndex(Node.TargetBone.BoneName);

	if(SourceIdx != INDEX_NONE && TargetIdx != INDEX_NONE)
	{
		FTransform SourceTM = SkelMeshComp->GetSpaceBases()[SourceIdx] * SkelMeshComp->ComponentToWorld;
		FTransform TargetTM = SkelMeshComp->GetSpaceBases()[TargetIdx] * SkelMeshComp->ComponentToWorld;

		PDI->DrawLine(TargetTM.GetLocation(), SourceTM.GetLocation(), FLinearColor(0.0f, 0.0f, 1.0f), SDPG_Foreground, 0.5f);

		FVector ToTarget = TargetTM.GetTranslation() - SourceTM.GetTranslation();
		FVector UnitToTarget = ToTarget;
		UnitToTarget.Normalize();
		FVector Midpoint = SourceTM.GetTranslation() + 0.5f * ToTarget + 0.5f * UnitToTarget * ArrowHeadHeight;

		FVector YAxis;
		FVector ZAxis;
		UnitToTarget.FindBestAxisVectors(YAxis, ZAxis);
		FMatrix ArrowMatrix(UnitToTarget, YAxis, ZAxis, Midpoint);

		DrawConnectedArrow(PDI, ArrowMatrix, FLinearColor(0.0f, 1.0f, 0.0), ArrowHeadHeight, ArrowHeadWidth, SDPG_Foreground);

		PDI->DrawPoint(SourceTM.GetTranslation(), FLinearColor(0.8f, 0.8f, 0.2f), 5.0f, SDPG_Foreground);
		PDI->DrawPoint(SourceTM.GetTranslation() + ToTarget, FLinearColor(0.8f, 0.8f, 0.2f), 5.0f, SDPG_Foreground);
	}
}
Esempio n. 12
0
void ASpellForceField::Tick( float DeltaSeconds )
{
	// push everything inside the sphere radially
	Super::Tick( DeltaSeconds );

	// search the proxbox for all actors in the volume.
	TArray<AActor*> actors;
	ProxSphere->GetOverlappingActors( actors );

	// damage each actor the sphere overlaps
	for( int c = 0; c < actors.Num(); c++ )
	{
		// don't damage the spell caster
		if( actors[ c ] != Caster )
		{
			// Only apply the damage if the box is overlapping the actors ROOT component.
			// This way damage doesn't get applied for simply overlapping the SightSphere.
			AMonster *monster = Cast<AMonster>( actors[c] );
			
			if( monster && ProxSphere->IsOverlappingComponent( monster->GetCapsuleComponent() ) )
			{
				FVector toMonster = monster->GetActorLocation() - GetActorLocation();
				toMonster.Normalize();
				monster->Knockback += toMonster*500;
			}
		}
	}
	
	TimeAlive += DeltaSeconds;
	if( TimeAlive > Duration )
	{
		Destroy();
	}
}
FVector UFlareSpacecraftNavigationSystem::GetTotalMaxThrustInAxis(TArray<UActorComponent*>& Engines, FVector Axis, bool WithOrbitalEngines) const
{
	Axis.Normalize();
	FVector TotalMaxThrust = FVector::ZeroVector;
	for (int32 i = 0; i < Engines.Num(); i++)
	{
		UFlareEngine* Engine = Cast<UFlareEngine>(Engines[i]);

		FVector WorldThrustAxis = Engine->GetThrustAxis();
		float Ratio = FVector::DotProduct(WorldThrustAxis, Axis);

		if (Engine->IsA(UFlareOrbitalEngine::StaticClass()))
		{
			if(WithOrbitalEngines && Ratio + 0.2 > 0)
			{
				TotalMaxThrust += WorldThrustAxis * Engine->GetMaxThrust() * (Ratio + 0.2);
			}
		}
		else
		{
			if (Ratio > 0)
			{
				TotalMaxThrust += WorldThrustAxis * Engine->GetMaxThrust() * Ratio;
			}
		}
	}

	return TotalMaxThrust;
}
void SAnimationSegmentViewport::InitSkeleton()
{
	UObject *Object = NULL;
	AnimRefPropertyHandle->GetValue(Object);
	UAnimSequenceBase *AnimSequence = Cast<UAnimSequenceBase>(Object);
	USkeleton *Skeleton = NULL;
	if(AnimSequence != NULL)
	{
		Skeleton = AnimSequence->GetSkeleton();
	}

	if( PreviewComponent != NULL && Skeleton != NULL )
	{
		USkeletalMesh* PreviewMesh = Skeleton->GetAssetPreviewMesh(AnimSequence);
		if (PreviewMesh)
		{
			UAnimSingleNodeInstance * Preview = PreviewComponent->PreviewInstance;
			if((Preview == NULL || Preview->GetCurrentAsset() != AnimSequence) ||
				(PreviewComponent->SkeletalMesh != PreviewMesh))
			{
				PreviewComponent->SetSkeletalMesh(PreviewMesh);
				PreviewComponent->EnablePreview(true, AnimSequence, NULL);
				PreviewComponent->PreviewInstance->SetLooping(true);

				//Place the camera at a good viewer position
				FVector NewPosition = LevelViewportClient->GetViewLocation();
				NewPosition.Normalize();
				LevelViewportClient->SetViewLocation(NewPosition * (PreviewMesh->GetImportedBounds().SphereRadius*1.5f));
			}
		}
	}

	TargetSkeleton = Skeleton;
}
	/** Initialization constructor. */
	FDirectionalLightSceneProxy(const UDirectionalLightComponent* Component):
		FLightSceneProxy(Component),
		bEnableLightShaftOcclusion(Component->bEnableLightShaftOcclusion),
		OcclusionMaskDarkness(Component->OcclusionMaskDarkness),
		OcclusionDepthRange(Component->OcclusionDepthRange),
		LightShaftOverrideDirection(Component->LightShaftOverrideDirection),
		DynamicShadowCascades(Component->DynamicShadowCascades),
		CascadeDistributionExponent(Component->CascadeDistributionExponent),
		CascadeTransitionFraction(Component->CascadeTransitionFraction),
		ShadowDistanceFadeoutFraction(Component->ShadowDistanceFadeoutFraction),
		bUseInsetShadowsForMovableObjects(Component->bUseInsetShadowsForMovableObjects),
		DistanceFieldShadowDistance(Component->bUseRayTracedDistanceFieldShadows ? Component->DistanceFieldShadowDistance : 0),
		LightSourceAngle(Component->LightSourceAngle)
	{
		LightShaftOverrideDirection.Normalize();

		if(Component->Mobility == EComponentMobility::Movable)
		{
			WholeSceneDynamicShadowRadius = Component->DynamicShadowDistanceMovableLight;
		}
		else
		{
			WholeSceneDynamicShadowRadius = Component->DynamicShadowDistanceStationaryLight;
		}
	}
float AGGJ16_Player::TakeDamage(float DamageAmount, struct FDamageEvent const &DamageEvent, class AController* EventInstigator, AActor* DamageCauser)
{
	if (!bDamaged)
	{
		health -= DamageAmount;
	}

	if (health <= 0)
	{
		playDeathAnim = true;
	}
	else
	{
		bDamaged = true;
	}

	if (DamageCauser)
	{
		FVector curForwardVector = DamageCauser->GetActorLocation() - this->GetActorLocation();
		curForwardVector.ProjectOnTo(FVector(1, 1, 0));
		curForwardVector.Normalize();
		LaunchCharacter(curForwardVector * KnockBackAlpha, true, true);
	}

	return 0.f;
	//do the pretty things
};
void DrawDebugDirectionalArrow(const UWorld* InWorld, FVector const& LineStart, FVector const& LineEnd, float ArrowSize, FColor const& Color, bool bPersistentLines, float LifeTime, uint8 DepthPriority)
{
	// no debug line drawing on dedicated server
	if (GEngine->GetNetMode(InWorld) != NM_DedicatedServer)
	{
		if (ArrowSize <= 0)
		{
			ArrowSize = 10.f;
		}

		DrawDebugLine(InWorld, LineStart, LineEnd, Color, bPersistentLines, LifeTime);

		FVector Dir = (LineEnd-LineStart);
		Dir.Normalize();
		FVector Up(0, 0, 1);
		FVector Right = Dir ^ Up;
		if (!Right.IsNormalized())
		{
			Dir.FindBestAxisVectors(Up, Right);
		}
		FVector Origin = FVector::ZeroVector;
		FMatrix TM;
		// get matrix with dir/right/up
		TM.SetAxes(&Dir, &Right, &Up, &Origin);

		// since dir is x direction, my arrow will be pointing +y, -x and -y, -x
		float ArrowSqrt = FMath::Sqrt(ArrowSize);
		FVector ArrowPos;
		DrawDebugLine(InWorld, LineEnd, LineEnd + TM.TransformPosition(FVector(-ArrowSqrt, ArrowSqrt, 0)), Color, bPersistentLines, LifeTime, DepthPriority);
		DrawDebugLine(InWorld, LineEnd, LineEnd + TM.TransformPosition(FVector(-ArrowSqrt, -ArrowSqrt, 0)), Color, bPersistentLines, LifeTime, DepthPriority);
	}
}
Esempio n. 18
0
void AAirCurrent::Tick(float DeltaSeconds)
{
	Super::Tick(DeltaSeconds);
	Duration += DeltaSeconds;
	if (HasAuthority())
	{
		TArray<AActor* > OverlappedActors;
		CollisionComp->GetOverlappingActors(OverlappedActors);
		for (int32 i = 0; i < OverlappedActors.Num(); i++)
		{
			ATotemCharacter* TotemCharacter = Cast<ATotemCharacter>(OverlappedActors[i]);
			if (TotemCharacter && !TotemCharacter->IsPendingKill() && !TotemCharacter->Invincible())
			{
				FRotator rot = GetActorRotation();
				FVector LaunchDir = rot.Vector();
				LaunchDir.Normalize(0.01f);
				LaunchDir *= LaunchSpeed;

				//EMovementMode mode = TotemCharacter->CharacterMovement->MovementMode;
				//TotemCharacter->LaunchCharacter(LaunchDir, true, true);
				//TotemCharacter->GetCharacterMovement()->Velocity += LaunchDir;
				TotemCharacter->LaunchCharacter(LaunchDir, false, false);
				//TotemCharacter->CharacterMovement->AddForce(LaunchDir);
				//TotemCharacter->CharacterMovement->SetMovementMode(mode);
			}
			
			//add a lot of type check, hope fix the crash
			UActorComponent* actorComp = OverlappedActors[i]->GetComponentByClass(UProjectileMovementComponent::StaticClass());
			if (actorComp !=nullptr)
			{
				UProjectileMovementComponent* movementComp = Cast<UProjectileMovementComponent>(actorComp);
				if (movementComp && !movementComp->IsPendingKill())
				{
					FRotator rot = GetActorRotation();
					FVector LaunchDir = rot.Vector();
					LaunchDir.Normalize(0.01f);
					if (movementComp)
					{
						LaunchDir *= movementComp->GetMaxSpeed();
						movementComp->Velocity = LaunchDir;
					}
				}
			}
			
		}
	}	
}
Esempio n. 19
0
FVector FGeomEdge::GetWidgetLocation()
{
	FVector dir = (GetParentObject()->VertexPool[ VertexIndices[1] ] - GetParentObject()->VertexPool[ VertexIndices[0] ]);
	const float dist = dir.Size() / 2;
	dir.Normalize();
	const FVector loc = GetParentObject()->VertexPool[ VertexIndices[0] ] + (dir * dist);
	return GetParentObject()->GetActualBrush()->ActorToWorld().TransformPosition( loc );
}
void ABranchingLinesActor::CreateSegments()
{
	// We create the branching structure by constantly subdividing a line between two points by creating a new point in the middle.
	// We then take that point and offset it in a random direction, by a random amount defined within limits.
	// Next we take both of the newly created line halves, and subdivide them the same way.
	// Each new midpoint also has a chance to create a new branch
	// TODO This should really be recursive
	Segments.Empty();
	float CurrentBranchOffset = MaxBranchOffset;

	if (bMaxBranchOffsetAsPercentageOfLength)
	{
		CurrentBranchOffset = (Start - End).Size() * (FMath::Clamp(MaxBranchOffset, 0.1f, 100.0f) / 100.0f);
	}

	// Pre-calc a few floats from percentages
	float ChangeOfFork = FMath::Clamp(ChanceOfForkPercentage, 0.0f, 100.0f) / 100.0f;
	float BranchOffsetReductionEachGeneration = FMath::Clamp(BranchOffsetReductionEachGenerationPercentage, 0.0f, 100.0f) / 100.0f;

	// Add the first segment which is simply between the start and end points
	Segments.Add(FBranchSegment(Start, End, TrunkWidth));

	for (int32 iGen = 0; iGen < Iterations; iGen++)
	{
		TArray<FBranchSegment> newGen;

		for (const FBranchSegment& EachSegment : Segments)
		{
			FVector Midpoint = (EachSegment.End + EachSegment.Start) / 2;

			// Offset the midpoint by a random number along the normal
			FVector normal = FVector::CrossProduct(EachSegment.End - EachSegment.Start, OffsetDirections[RngStream.RandRange(0, 1)]);
			normal.Normalize();
			Midpoint += normal * RngStream.RandRange(-CurrentBranchOffset, CurrentBranchOffset);

			 // Create two new segments
			newGen.Add(FBranchSegment(EachSegment.Start, Midpoint, EachSegment.Width, EachSegment.ForkGeneration));
			newGen.Add(FBranchSegment(Midpoint, EachSegment.End, EachSegment.Width, EachSegment.ForkGeneration));

			// Chance of fork?
			if (RngStream.FRand() > (1 - ChangeOfFork))
			{
				// TODO Normalize the direction vector and calculate a new total length and then subdiv that for X generations
				FVector direction = Midpoint - EachSegment.Start;
				FVector splitEnd = (direction * RngStream.FRandRange(ForkLengthMin, ForkLengthMax)).RotateAngleAxis(RngStream.FRandRange(ForkRotationMin, ForkRotationMax), OffsetDirections[RngStream.RandRange(0, 1)]) + Midpoint;
				newGen.Add(FBranchSegment(Midpoint, splitEnd, EachSegment.Width * WidthReductionOnFork, EachSegment.ForkGeneration + 1));
			}
		}

		Segments.Empty();
		Segments = newGen;

		// Reduce the offset slightly each generation
		CurrentBranchOffset = CurrentBranchOffset * BranchOffsetReductionEachGeneration;
	}
}
	void UpdateLightShaftOverrideDirection_GameThread(const UDirectionalLightComponent* Component)
	{
		FVector NewLightShaftOverrideDirection = Component->LightShaftOverrideDirection;
		NewLightShaftOverrideDirection.Normalize();
		ENQUEUE_UNIQUE_RENDER_COMMAND_TWOPARAMETER(
			FUpdateLightShaftOverrideDirectionCommand,
			FDirectionalLightSceneProxy*,Proxy,this,
			FVector,NewLightShaftOverrideDirection,NewLightShaftOverrideDirection,
		{
			Proxy->UpdateLightShaftOverrideDirection_RenderThread(NewLightShaftOverrideDirection);
		});
void ASWeaponInstant::SimulateInstantHit(const FVector& Origin)
{
	const FVector StartTrace = Origin;
	const FVector AimDir = GetAdjustedAim();
	const FVector EndTrace = StartTrace + (AimDir * WeaponRange);

 	const FHitResult Impact = WeaponTrace(StartTrace, EndTrace);
	if (Impact.bBlockingHit)
	{
		SpawnImpactEffects(Impact);
		SpawnTrailEffects(Impact.ImpactPoint);
	}
	else
	{
		SpawnTrailEffects(EndTrace);
	}

	// Do not spawn near-hit if we actually hit a pawn
	if (Impact.GetActor() && Impact.GetActor()->IsA(ASCharacter::StaticClass()))
	{
		return;
	}

	for (FConstPawnIterator It = GetWorld()->GetPawnIterator(); It; It++)
	{
		// Find a locally controlled pawn that is not the instigator of the hit.
		ASCharacter* OtherPawn = Cast<ASCharacter>(*It);
		if (OtherPawn && OtherPawn != GetPawnOwner() && OtherPawn->IsLocallyControlled())
		{
			// Calculate shortest distance to point. (using the estimated eye height)
			const float DistanceToPawn = FVector::CrossProduct(AimDir, OtherPawn->GetActorLocation() - Origin).Size();

			/* Owner can be lost before client gets to simulate the hit. */
			ASCharacter* P = GetPawnOwner();
			if (P)
			{
				FVector LookAt = (OtherPawn->GetActorLocation() - GetPawnOwner()->GetActorLocation());
				LookAt.Normalize();
				float LookDot = FVector::DotProduct(AimDir, LookAt);

				if (DistanceToPawn < NearHitMaxDistance && LookDot > 0)
				{
					// TODO: Play at nearest "almost" hit location.
					const FVector SoundLocation = Origin + (AimDir * DistanceToPawn);

					// Volume is based on distance to missed shot
					float Volume = FMath::Clamp(1 - (DistanceToPawn / NearHitMaxDistance), 0.1f, 1.0f);

					UGameplayStatics::PlaySoundAtLocation(this, NearHitSound, /*SoundLocation*/ OtherPawn->GetActorLocation(), Volume);
				}
			}
		}
	}
}
Esempio n. 23
0
void UEditorEngine::polySplitOverlappingEdges( TArray<FPoly>* InPolyList, TArray<FPoly>* InResult )
{
	InResult->Empty();

	for( int32 poly = 0 ; poly < InPolyList->Num() ; poly++ )
	{
		FPoly* SrcPoly = &(*InPolyList)[poly];
		FPoly NewPoly = *SrcPoly;

		for( int32 edge = 0 ; edge < SrcPoly->Vertices.Num() ; edge++ )
		{
			FEdge SrcEdge = FEdge( SrcPoly->Vertices[edge], SrcPoly->Vertices[ edge+1 < SrcPoly->Vertices.Num() ? edge+1 : 0 ] );
			FPlane SrcEdgePlane( SrcEdge.Vertex[0], SrcEdge.Vertex[1], SrcEdge.Vertex[0] + (SrcPoly->Normal * 16) );

			for( int32 poly2 = 0 ; poly2 < InPolyList->Num() ; poly2++ )
			{
				FPoly* CmpPoly = &(*InPolyList)[poly2];

				// We can't compare to ourselves.
				if( CmpPoly == SrcPoly )
					continue;

				for( int32 edge2 = 0 ; edge2 < CmpPoly->Vertices.Num() ; edge2++ )
				{
					FEdge CmpEdge = FEdge( CmpPoly->Vertices[edge2], CmpPoly->Vertices[ edge2+1 < CmpPoly->Vertices.Num() ? edge2+1 : 0 ] );

					// If both vertices on this edge lie on the same plane as the original edge, create
					// a sphere around the original 2 vertices.  If either of this edges vertices are inside of
					// that sphere, we need to split the original edge by adding a vertex to it's poly.
					if( FMath::Abs( FVector::PointPlaneDist( CmpEdge.Vertex[0], SrcEdge.Vertex[0], SrcEdgePlane ) ) < THRESH_POINT_ON_PLANE
							&& FMath::Abs( FVector::PointPlaneDist( CmpEdge.Vertex[1], SrcEdge.Vertex[0], SrcEdgePlane ) ) < THRESH_POINT_ON_PLANE )
					{
						//
						// Check THIS edge against the SOURCE edge
						//

						FVector Dir = SrcEdge.Vertex[1] - SrcEdge.Vertex[0];
						Dir.Normalize();
						float Dist = FVector::Dist( SrcEdge.Vertex[1], SrcEdge.Vertex[0] );
						FVector Origin = SrcEdge.Vertex[0] + (Dir * (Dist / 2.0f));
						float Radius = Dist / 2.0f;

						for( int32 vtx = 0 ; vtx < 2 ; vtx++ )
							if( FVector::Dist( Origin, CmpEdge.Vertex[vtx] ) && FVector::Dist( Origin, CmpEdge.Vertex[vtx] ) < Radius )
								NewPoly.InsertVertex( edge2+1, CmpEdge.Vertex[vtx] );
					}
				}
			}
		}

		new(*InResult)FPoly( NewPoly );
	}

}
Esempio n. 24
0
void AGameObject::Walk( float t )
{
  CheckWaypoint();

  // Alter destination based on locations of other units.
  FVector ToDest = Dest - Pos;
  
  // Clamp travel length so that we can't overshoot destination
  if( float Len = ToDest.Size() )
  {
    Dir = ToDest / Len; // normalize
    if( !Stats.SpeedMax )  error( FS("%s had 0 speed", *GetName()) );
    
    // I am maxing out the speed here.
    Speed = Stats.SpeedMax;

    // The direction of travel is modified by repulsion forces
    FVector repulsionForces = GetRepulsionForcesFromOverlappedUnits();
    FVector modDir = Dir + repulsionForces;
    modDir.Normalize();
    FVector Vel = modDir*Speed;
    //Game->flycam->DrawDebug( Pos, Pos + Vel, 5.f, FLinearColor::Red, 0.f );
    FVector travel = Vel*t;

    // If travel exceeds destination, then jump to dest,
    // so we don't jitter over the final position.
    if( Len < travel.Size() )
    {
      // snap to position & stop moving.
      Pos = Dest; // we are @ destination.
      travel = ToDest; // This is the displacement we actually moved.
      Speed = 0;
    }
    else
    {
      Pos += travel;
      if( Grounds )
      {
        FVector newPos = Pos + UnitZ * 10.f;
        // Travel in direction plus some amount straight up.
        // The straight up amount ensures that the unit doesn't sink underground
        if( Game->flycam->SetOnGround( newPos ) )  Pos = newPos;
        else  error( FS( "%s Object was trying to leave the ground plane.", *GetName() ) );
      }
      SetRot( Dir.Rotation() );
    }
  }
  else
  {
    // We're at the destination, so the velocity becomes 0
    Speed = 0.f;
  }
}
// Render a coordinate system indicator
void USkeletalMeshComponent::RenderAxisGizmo( const FTransform& Transform, UCanvas* Canvas ) const
{
	// Display colored coordinate system axes for this joint.
	const float AxisLength = 3.75f;
	const FVector Origin = Transform.GetLocation();

	// Red = X
	FVector XAxis = Transform.TransformVector( FVector(1.0f,0.0f,0.0f) );
	XAxis.Normalize();
	DrawDebugCanvasLine(Canvas, Origin, Origin + XAxis * AxisLength, FLinearColor( 1.f, 0.3f, 0.3f));		

	// Green = Y
	FVector YAxis = Transform.TransformVector( FVector(0.0f,1.0f,0.0f) );
	YAxis.Normalize();
	DrawDebugCanvasLine(Canvas, Origin, Origin + YAxis * AxisLength, FLinearColor( 0.3f, 1.f, 0.3f));	

	// Blue = Z
	FVector ZAxis = Transform.TransformVector( FVector(0.0f,0.0f,1.0f) );
	ZAxis.Normalize();
	DrawDebugCanvasLine(Canvas, Origin, Origin + ZAxis * AxisLength, FLinearColor( 0.3f, 0.3f, 1.f));	
}
void UEnemyRoadSplineComponent::MoveCharacterlongSplineTrack(ACharacter* Actor)
{
	if (RoadSpline)
	{
		FVector DirectionToRun = RoadSpline->CalDirectionToRun(Actor, this);
		DirectionToRun.Normalize();
		DirectionToRun.Z = 0;

		Actor->AddMovementInput(DirectionToRun, 10);
		SetActorRotationMulticast(DirectionToRun.Rotation());
	}
}
float UFlareSpacecraftNavigationSystem::GetTotalMaxTorqueInAxis(TArray<UActorComponent*>& Engines, FVector TorqueAxis, bool WithDamages) const
{
	TorqueAxis.Normalize();
	float TotalMaxTorque = 0;

	for (int32 i = 0; i < Engines.Num(); i++) {
		UFlareEngine* Engine = Cast<UFlareEngine>(Engines[i]);

		// Ignore orbital engines for torque computation
		if (Engine->IsA(UFlareOrbitalEngine::StaticClass()))
		{
		  continue;
		}

		float MaxThrust = (WithDamages ? Engine->GetMaxThrust() : Engine->GetInitialMaxThrust());

		if (MaxThrust == 0)
		{
			// Not controlable engine
			continue;
		}

		FVector EngineOffset = (Engine->GetComponentLocation() - COM) / 100;

		FVector WorldThrustAxis = Engine->GetThrustAxis();
		WorldThrustAxis.Normalize();
		FVector TorqueDirection = FVector::CrossProduct(EngineOffset, WorldThrustAxis);
		TorqueDirection.Normalize();

		float Ratio = FVector::DotProduct(TorqueAxis, TorqueDirection);

		if (Ratio > 0)
		{
			TotalMaxTorque += FVector::CrossProduct(EngineOffset, WorldThrustAxis).Size() * MaxThrust * Ratio;
		}

	}

	return TotalMaxTorque;
}
void AMMO_Character::MeleeAttackRaycasts()
{
	FVector BaseSocketLoc = Player_SkeletalMeshComponent->GetSocketLocation(FName("Sword_joint"));
	FVector TipSocketLoc = Player_SkeletalMeshComponent->GetSocketLocation(FName("Sword_Edge"));

	const int sub = 32;
	float curLength = (BaseSocketLoc - TipSocketLoc).Size() * 2;
	float prevLength = (prevBase - prevTip).Size();
	for (int i = 1; i < sub; i++)
	{
		FVector tmpBase = FMath::Lerp(BaseSocketLoc, prevBase, i / float(sub));
		FVector tmpTip = FMath::Lerp(TipSocketLoc, prevTip, i / float(sub));
		FVector tmpOff = (tmpTip - tmpBase);
		tmpOff.Normalize();
	}
	prevBase = BaseSocketLoc;
	prevTip = TipSocketLoc;

	FHitResult Hit;
	FCollisionQueryParams ColParams = FCollisionQueryParams(FName("NoName"), false, GetOwner());
	ColParams.AddIgnoredActor(GetOwner());
	ColParams.AddIgnoredActor(this);
	if (GetWorld()->LineTraceSingleByChannel(Hit, BaseSocketLoc, TipSocketLoc, ECollisionChannel::ECC_WorldDynamic, ColParams))
	{
		if (Hit.Actor != GetOwner() && AnimInstance->bCanDamageMelee)
		{
			if (Cast<AMMO_Mob_Character>(Hit.Actor.Get()))
			{
				if (!Cast<AMMO_Mob_Character>(Hit.Actor.Get())->bIsDead && !Cast<AMMO_Mob_Character>(Hit.Actor.Get())->bIsImmunized)
				{
					if (Role < ROLE_Authority)
					{
						AnimInstance->bCanDamageMelee = false;
						GetDamage(BaseAttack, AttackBonusMin, AttackBonusMax, Cast<AMMO_Mob_Character>(Hit.Actor.Get()));
					}
				}
			}
			else if (Cast<ABoss>(Hit.Actor.Get()))
			{
				if (!Cast<ABoss>(Hit.Actor.Get())->bIsDead)
				{
					if (Role < ROLE_Authority)
					{
						AnimInstance->bCanDamageMelee = false;

						GetDamage_Boss(BaseAttack, AttackBonusMin, AttackBonusMax, Cast<ABoss>(Hit.Actor.Get()));
					}
				}
			}
		}
	}
}
Esempio n. 29
0
// Called every frame
void AMovingPlatform::Tick( float DeltaTime )
{
	Super::Tick( DeltaTime );
	if (bIsActive)
	{
		if (GetActorLocation().Equals(Target1, 2.0f)) CurrentTarget = Target2;
		else if (GetActorLocation().Equals(Target2, 2.0f)) CurrentTarget = Target1;
		FVector Direction = CurrentTarget - GetActorLocation();
		Direction.Normalize();
		Direction *= PlatformSpeed * DeltaTime;
		AddActorWorldTransform(FTransform(Direction));
	}
}
Esempio n. 30
0
// Called every frame
void AFlySkillActor::Tick( float DeltaTime )
{
	Super::Tick( DeltaTime );
	if (!IsReadyToStart)
	{
		return;
	}
	if (AttackCollision.Num() > 0)
	{
		Injury();
	}
	float move = DeltaTime * MoveSpeed;
	FVector ourpos = GetActorLocation();
	FVector dstpos;
	if (UseTargetLocation)
	{
		dstpos = TargetLocation;
	}
	else
	{
		dstpos = TargetActor->GetActorLocation();;
	}
	float dis = FVector::Dist(ourpos, dstpos);
	if (move >= dis)
	{
		SetActorLocation(dstpos);
	}
	else
	{
		FVector dir = dstpos - ourpos;
		dir.Normalize();
		dir *= move;
		SetActorLocation(ourpos + dir);
	}
	if (dis < 1 && !PrepareDestory)
	{
		BulletParticle->SetActive(false);
		PrepareDestory = true;
		DestoryCount = 0;
	}
	if (PrepareDestory)
	{
		DestoryCount += DeltaTime;
		if (DestoryCount >= DestroyDelay)
		{
			this->Destroy();
		}
	}
}