bool ABaseCharacter::CanCharacterSprint()const { FVector ForwardVector = GetActorForwardVector(); //normalized forward direction of the player FVector VelocityVector = GetCharacterMovement()->Velocity.GetSafeNormal(); //the normalized direction in which the player is moving bool IsMovingForward = false; bool IsMovingOnRightVector = false; float p = FVector::DotProduct(ForwardVector, VelocityVector); //cosine of angle between forward vector and velocity vector //p = 1 if player is moving forward //p = -1 if player is moving backward //p = 0 if player is moving right or left //we don't get exact values due to limited precision so check if p is nearly equal to 1, -1 or 0 if (p > 0.7f) //check if dot product is nearly one IsMovingForward = true; if (p < 0.1f) //check if dot product is nearly zero IsMovingOnRightVector = true; return !bIsCrouched && //Is not crouching !GetCharacterMovement()->IsFalling() && //Is not Falling (GetCharacterMovement()->Velocity.SizeSquared() != 0.0f) && //Is not sationary IsMovingForward && //Is moving forward and not backward !IsMovingOnRightVector; //Is NOT moving right or left }
void AMagnetTile::PullBall( ABallPawn* ball ) { auto prim = Cast<UPrimitiveComponent>( ball->GetRootComponent() ); UWorld* world = GetWorld(); auto DeltaTime = world->DeltaTimeSeconds; AProjectTapGameState* gameState; if ( world != nullptr && ( gameState = world->GetGameState<AProjectTapGameState>() ) != nullptr && gameState->SetMagnetTile( this ) != this ) { FVector angular = FVector::ZeroVector; prim->SetPhysicsAngularVelocity( angular ); float distanceAtNormal = FVector::DotProduct( ball->GetActorLocation() - GetActorLocation() , GetActorForwardVector() ); FVector normalLoc = ( distanceAtNormal * GetActorForwardVector() ) + GetActorLocation(); FVector normalToBall = ball->GetActorLocation() - normalLoc; float dist = normalToBall.Size(); if ( dist > centerTolerance ) { FVector toAdd = dist * -normalToBall.GetSafeNormal(); toAdd.Z = 0; prim->AddRelativeLocation( toAdd ); } } if ( isVertical ) { attractionSpeed *= verticalForceMultiplier; } float originalSpeed = prim->GetPhysicsLinearVelocity().Size(); float newSpeed = attractionSpeed + originalSpeed; prim->SetPhysicsLinearVelocity(newSpeed * -GetActorForwardVector()); }
void ACVehicleSpawner::OnTimer() { FTimerHandle Handle; if (!Active || Paused) { GetWorld()->GetTimerManager().SetTimer(Handle, this, &ACVehicleSpawner::OnTimer, GetTimeWait(), false); return; } if (Bucket.Num() == 0) { GEngine->AddOnScreenDebugMessage(-1, 15.f, FColor::Red, TEXT("You need to add Vehicle Types to the Vehicle Spawner")); } FVector StartTrace = GetActorLocation() - GetActorForwardVector() * 400 + FVector(0, 0, 100); FVector EndTrace = GetActorLocation() + GetActorForwardVector() * 400 + FVector(0, 0, 100); if (GetWorld()->LineTraceTest( StartTrace, EndTrace, ECollisionChannel::ECC_Vehicle, FCollisionQueryParams(), FCollisionResponseParams() )) { GetWorld()->GetTimerManager().SetTimer(Handle, this, &ACVehicleSpawner::OnTimer, 0.1f, false); return; } FActorSpawnParameters spawnParameters; spawnParameters.bNoCollisionFail = true; spawnParameters.Owner = this; spawnParameters.Instigator = NULL; spawnParameters.bDeferConstruction = false; int32 BucketIndex = FMath::RandRange(0, Bucket.Num() - 1); EVehicleType VehicleType = Bucket[BucketIndex]; Bucket.RemoveAtSwap(BucketIndex); if (Bucket.Num() == 0) { TurnBucket(); } TSubclassOf<class AFlockingVehicle> Type = VehicleTypeClass[(uint8)VehicleType]; AFlockingVehicle* NewVehicle = GetWorld()->SpawnActor<AFlockingVehicle>(Type, GetActorLocation(), GetActorRotation(), spawnParameters); NewVehicle->SetFlockingState(FlockingState); NewVehicle->SpawnDefaultController(); NewVehicle->GetMesh()->SetAllPhysicsLinearVelocity(GetActorForwardVector() * StartSpeed / 0.036); if (NewVehicle->VehicleType != VehicleType) { GEngine->AddOnScreenDebugMessage(-1, 15.f, FColor::Red, TEXT("Vehicle Type is not correct.")); } GetWorld()->GetTimerManager().SetTimer(Handle, this, &ACVehicleSpawner::OnTimer, GetTimeWait(), false); if (VehicleTypeMaterials.Contains((uint8)VehicleType)) { auto Materials = VehicleTypeMaterials[(uint8)VehicleType]; int32 Index = FMath::RandRange(0, Materials.Num() - 1); UMaterial* Material = Materials[Index]; NewVehicle->GetMesh()->SetMaterial(2, Material); NewVehicle->ColorMaterialIndex = Index; } }
void ACoverActor::DetermineMovementDirection(FVector& MovementDirection, FRotator& FacingDirection) { FName NearbySocket = GetNearbySocket(); AActor* Char = UGameplayStatics::GetPlayerCharacter(GetWorld(), 0); //Determine the movement and facing direction of the player, based on the described logic //The way that we're deciding the facing direction is similar to the way we've decided //the movement direction if (NearbySocket.IsEqual("ForwardSocket")) { MovementDirection = -GetActorRightVector(); FacingDirection = GetActorRotation(); } else if (NearbySocket.IsEqual("BackwardSocket")) { MovementDirection = GetActorRightVector(); FacingDirection = GetActorRotation() + FRotator(0, 180, 0); } else if (NearbySocket.IsEqual("RightSocket")) { MovementDirection = GetActorForwardVector(); FacingDirection = GetActorRotation() + FRotator(0, 90, 0); } else { MovementDirection = -GetActorForwardVector(); FacingDirection = GetActorRotation() + FRotator(0, -90.f, 0); } }
void AGameplayAbilityWorldReticle::FaceTowardSource(bool bFaceIn2D) { if (TargetingActor) { if (bFaceIn2D) { FVector FacingVector = (TargetingActor->StartLocation.GetTargetingTransform().GetLocation() - GetActorLocation()).GetSafeNormal2D(); if (FacingVector.IsZero()) { FacingVector = -GetActorForwardVector().GetSafeNormal2D(); } if (!FacingVector.IsZero()) { SetActorRotation(FacingVector.Rotation()); } } else { FVector FacingVector = (TargetingActor->StartLocation.GetTargetingTransform().GetLocation() - GetActorLocation()).GetSafeNormal(); if (FacingVector.IsZero()) { FacingVector = -GetActorForwardVector().GetSafeNormal(); } SetActorRotation(FacingVector.Rotation()); } } }
void APawnCharacter::MoveForward(float AxisValue) { if (OurMovementComponent && (OurMovementComponent->UpdatedComponent == RootComponent)) { OurMovementComponent->AddInputVector(GetActorForwardVector() * AxisValue); } }
void ACloud10Character::bounceJump(float Value) { float curJumpVelocity = Value; float jumpVelocity; GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Yellow, TEXT("bounceJump")); const FVector ForwardDir = GetActorForwardVector(); /*bounceCount++; if(bounceCount > 1) { jumpVelocity = jumpVelocity * 1.3; }*/ //if player has landed, reset jumpVelocity /*if (curJumpVelocity < baseJumpForce) jumpVelocity = baseJumpForce;*/ //thresholds for jump velocity's that convert to force? //max jump? if (curJumpVelocity >= 3000) { curJumpVelocity = 3000; } //add only player's vertical speed to the last jump Velocity jumpVelocity = FMath().Abs(curJumpVelocity) + baseJumpForce; FVector AddForce = FVector(0, 0, 1) * jumpVelocity; //separate max walk speed from max fall speed //GetCharacterMovement()->MaxWalkSpeed = AddForce.Size(); //convert float to string FString tempString = FString::SanitizeFloat(AddForce.Size()); GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Yellow, *tempString); LaunchCharacter(AddForce, false, true); //bPressedJump = true; //jumpVelocity = 600; }
void AUModCharacter::MoveForward(float Value) { if (Value != 0.0f) { AddMovementInput(GetActorForwardVector(), Value); } }
void ADuckTower::Shoot(float distance) { /* const FName filename = FName(TEXT("Blueprint'/Game/Blueprints/PickUp.PickUp'")); FVector loc = GetAttachParentActor()->GetActorLocation(); FRotator rot = GetAttachParentActor()->GetActorRotation(); SpawnBP(GetWorld(), (UClass*)LoadObjFromPath<UBlueprint>(&filename), loc, rot); */ APawn *player = UGameplayStatics::GetPlayerController(GetWorld(), 1)->GetControlledPawn(); int randomValue = distance / 10000; FVector vec = player->GetActorLocation() + FVector(FMath::RandRange(-randomValue, randomValue), FMath::RandRange(-randomValue, randomValue), 0.0f); //+ player->GetRootPrimitiveComponent()->GetPhysicsLinearVelocity() *DeltaSeconds * 10; FVector vec2 = GetActorLocation(); FVector Direction = vec - vec2; FRotator test = FRotationMatrix::MakeFromX(Direction).Rotator(); FRotator test2 = FRotator(1.0f, 0.0f, 0.0f); FRotator finalrot = FRotator(test.Quaternion() * test2.Quaternion()); FVector forward = GetActorForwardVector(); finalrot.Roll = -finalrot.Roll; finalrot.Yaw = -finalrot.Yaw; finalrot.Pitch = -finalrot.Pitch; FVector loc = GetActorLocation() + forward * 500.0f; FRotator rot = GetActorRotation(); AActor* actor = GetWorld()->SpawnActor<AActor>(BulletBlueprint, loc, GetActorRotation()); actor->SetActorScale3D(FVector(3.0f, 3.0f, 3.0f)); //actor->GetRootPrimitiveComponent()->AddImpulse(actor->GetActorForwardVector()* 5000.0f); //actor->GetRootPrimitiveComponent()->SetPhysicsLinearVelocity(actor->GetActorForwardVector()*10000.0f); //* (distance/10000 * 1.0f)); }
void APlayerOvi::CalculateOrientation(){ FVector forward = GetActorForwardVector(); FVector up = GetActorUpVector(); float dotForward = FVector::DotProduct(GetActorLocation(), forward); if (dotForward > m_limit && m_state == States::RIGHT) Rotate(FVector(0, 0, -90)); if (dotForward > m_limit && m_state == States::LEFT) Rotate(FVector(0, 0, 90)); float dotUp = FVector::DotProduct(GetActorLocation(), up); float val = 0; if (dotUp > m_limit || dotUp < -m_limit) { bool toUp = dotUp > m_limit; val = (toUp) ? 90 : -90; if (m_state == States::RIGHT) Rotate(FVector(-val, 0, 0)); else if (m_state == States::LEFT) Rotate(FVector(val, 0, 0)); } AjustPosition(); }
void AUnreal4FPSGameCharacter::MoveForward(float Value) { if (Value != 0.0f) { // add movement in that direction AddMovementInput(GetActorForwardVector(), Value); } }
void ASterlingResortsCharacter::MoveForward(float Value) { if (Value != 0.0f) { // add movement in that direction AddMovementInput(GetActorForwardVector(), Value); } }
void AGestureRecognizerCharacter::MoveForward(float Value) { if (Value != 0.0f) { // add movement in that direction AddMovementInput(GetActorForwardVector(), Value); } }
void AGearVR_QSCharacter::MoveForward(float Value) { if (Value != 0.0f) { // add movement in that direction AddMovementInpVR(GetActorForwardVector(), Value); } }
void AInventoryPrototypeCharacter::MoveForward(float Value) { if (Value != 0.0f) { // add movement in that direction AddMovementInput(GetActorForwardVector(), Value); } }
void AShaderPluginDemoCharacter::MoveForward(float Value) { if (Value != 0.0f) { // add movement in that direction AddMovementInput(GetActorForwardVector(), Value); } }
void AMiniJamJuly2015Character::MoveForward(float Value) { if (Value != 0.0f) { // add movement in that direction AddMovementInput(GetActorForwardVector(), Value); } }
void ASGJAM16_SPOOPYCharacter::MoveForward(float Value) { if (Value != 0.0f) { // add movement in that direction AddMovementInput(GetActorForwardVector(), Value); } }
void AFP_FirstPersonCharacter::MoveForward(float Value) { if (Value != 0.0f) { // Add movement in that direction AddMovementInput(GetActorForwardVector(), Value); } }
void AMobileOpenCVCharacter::MoveForward(float Value) { if (Value != 0.0f) { // add movement in that direction AddMovementInput(GetActorForwardVector(), Value); } }
void APlayerCharacter::MoveForward(float val) { if (val != 0.0f) { FVector dir = GetActorForwardVector(); AddMovementInput(dir, val, false); } }
void ATotemCharacter::MoveForward(float Value) { if (Value != 0.0f && bCanMove && bAcceptMoveInput) { // add movement in that direction AddMovementInput(GetActorForwardVector(), Value * MoveSpeedScale); } }
void AAvatar::MoveForward(float amount) { if (Controller && amount) { FVector fwd = GetActorForwardVector(); AddMovementInput(fwd, amount); } }
void AVertexColorSpreadCharacter::MoveForward(float Value) { if (Value != 0.0f) { // add movement in that direction AddMovementInput(GetActorForwardVector(), Value); } }
void AUDKPresentationCharacter::MoveForward(float Value) { if (Value != 0.0f) { // add movement in that direction AddMovementInput(GetActorForwardVector(), Value); } }
// Handles the event when the MoveForward buttons are pressed void ASpectatorCharacter::MoveForward(float AxisValue) { if (AxisValue != 0.0f) { //UE_LOG(LogTemp, Warning, TEXT("Movement Pressed AxisValue = %f:"), AxisValue); AddMovementInput(GetActorForwardVector(), AxisValue); } }
/*Description: Moves the player forward and backwards*/ void APoseidonCharacter::MoveForward(float value) { if (value != 0.0f && !mWasGrappleShot && !mCameraLock) { AddMovementInput(GetActorForwardVector(), value); value = FMath::Abs(value); PlayerController->ClientPlayCameraShake(HeadBobClass, value); //ReportNoise("Event_PosStep", 0.0f); } }
void AShip::calculateMovement(){ //GEngine->AddOnScreenDebugMessage(-1, 5.0, FColor::Green, FString(engines)); FVector direction = GetActorForwardVector(); if (engines && engines->getThrottle() > 0){ direction.X *= engines->getThrottle() * engines->getPower(); direction.Z *= engines->getThrottle() * engines->getPower(); direction.Y += 0.f; GetRootPrimitiveComponent()->AddForce(direction); } }
void AAvatar::MoveForward(float amount) { if (inventory_showing) { return; } if (Controller && amount) { FVector forward = GetActorForwardVector(); AddMovementInput(forward, amount); } }
void ACloud10Character::DiveRight(float Value, float deltaSeconds) { float prevYaw = GetActorRotation().Yaw; float minDeltaYaw = minYaw - prevYaw; float maxDeltaYaw = maxYaw - prevYaw; //roll character in an angle front and back curYawAmt = Value; /* const FRotator Rotation = GetActorRotation(); FRotator dRotation(0, 0, 0); //curYawAmt * rotationRate const FVector Direction = FVector(0.0f, (curYawAmt * rotationRate), 0.0f) ;//= FRotationMatrix(Rotation).GetUnitAxis(EAxis::Z); dRotation = Direction.Rotation(); dRotation.Yaw = FMath::ClampAngle(dRotation.Yaw, minDeltaYaw, maxDeltaYaw); //dRotation.Yaw = curYawAmt + Direction.Z;//FMath::ClampAngle(curYawAmt * Direction.Z, minDeltaYaw, maxDeltaYaw); //Controller->SetControlRotation(dRotation); //AddControllerYawInput(dRotation.Yaw); FRotator tempRotation = FMath::RInterpTo(Rotation, dRotation, 3, 0); AddActorLocalRotation(tempRotation); //AddActorWorldRotation(dRotation); */ FRotator Rotation = GetActorRotation(); FVector moveDirection = FRotationMatrix(Rotation).GetUnitAxis(EAxis::Z); //velocity movement based upon forward vector in left/right direction const FVector ForwardDir = GetActorForwardVector(); FVector AddPos = ForwardDir; AddPos = moveDirection * AddPos; //add forward velocity and value of direction AddMovementInput(AddPos, Value); //adjust yaw /*float val = 30; float axisVal; UStaticMeshComponent* smc = Cast<UStaticMeshComponent>(RootComponent); axisVal = Value * val; //add tilting movement control on left & right FRotator Rotation = GetActorRotation(); Rotation.Roll = Value; AddActorLocalRotation(Rotation);*/ //curRollAmt = Value; // find out which way is right /*const FRotator Rotation = Controller->GetControlRotation(); const FRotator YawRotation(0, Rotation.Yaw, 0); // get right vector const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y); //smc->SetPhysicsLinearVelocity(Direction * axisVal); AddControllerYawInput((Direction * axisVal));*/ }