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 ABrainNormalInteractiveObject::BeginPlay() { Super::BeginPlay(); int8 flags = (_canBeRotate ? EAction::ROTATE : 0) | (_canBeTranslate ? EAction::TRANSLATE : 0) | (_canBeScale ? EAction::SCALE : 0) | (_canBeShear ? EAction::SHEAR : 0); _actions = FObjectAction(flags); // Init Rotate _currentRotation = GetActorRotation(); _targetRotation = GetActorRotation(); // Init Translate _currentTranslation = GetActorLocation(); _targetTranslation = GetActorLocation(); // Init Scale _targetScale = _initScale; _currentScale = _initScale; // Init Shear _currentShearFirstAxis = 0; _currentShearSecondAxis = 0; _targetShearFirstAxis = 0; _targetShearSecondAxis = 0; _cachedTransform = GetTransform(); if (this->GetClass()->ImplementsInterface(UBrainSaveInterface::StaticClass())) Load(); }
void AZombieShooterCharacter::ServerPerformAttack_Implementation(){ //Perform the actual attack here UE_LOG(LogTemp, Warning, TEXT("Server Performing attack!")); //In final product, will call the currently equipped weapon's fire function //For now, just fire a basic projectile if (ProjectileClass != NULL) { //MuzzleRotation.Pitch += 10.0f; UWorld* const World = GetWorld(); if (World) { FActorSpawnParameters SpawnParams; SpawnParams.Owner = this; SpawnParams.Instigator = Instigator; //Spawn projectile at muzzle FVector FireLocation = GetActorLocation() + FTransform(GetActorRotation()).TransformVector(FVector(25.0f, 0.0f, 0.0f)); Projectile = World->SpawnActor<AProjectile>(ProjectileClass, FireLocation, GetActorRotation(), SpawnParams); if (Projectile) { //Find launch direction FVector const LaunchDir = GetActorRotation().Vector(); //FVector const LaunchDir = CameraBoom->GetComponentRotation().Vector(); Projectile->SetReplicates(true); Projectile->InitVelocity(LaunchDir); } } } }
void AFireDart::OnHit_Implementation(AActor * OtherActor) { if (OtherActor != GetOwner()) { ABanditCharacter* Bandit = Cast<ABanditCharacter>(OtherActor); ABaseTicker* Ticker = Cast<ABaseTicker>(OtherActor); if (Bandit) { if (Explosion) { UWorld* const World = GetWorld(); const FVector SpawnLocation = GetActorLocation(); const FRotator SpawnRotation = GetActorRotation(); World->SpawnActor<AActor>(Explosion, SpawnLocation,SpawnRotation); UGameplayStatics::ApplyDamage(Bandit, Damage, this->GetInstigatorController(), this, UDamageType::StaticClass()); this->Destroy(); } } else if (Ticker) { if (Explosion) { UWorld* const World = GetWorld(); const FVector SpawnLocation = GetActorLocation(); const FRotator SpawnRotation = GetActorRotation(); World->SpawnActor<AActor>(Explosion, SpawnLocation, SpawnRotation); UGameplayStatics::ApplyDamage(Ticker, Damage, this->GetInstigatorController(), this, UDamageType::StaticClass()); this->Destroy(); } } } }
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)); }
FRotator AGGJ16_Player::CalculateTargetRotation() { float Yaw = FMath::RadiansToDegrees(FMath::Atan2(CurrentInputRotation.Y, CurrentInputRotation.X)); SetActorRotation(FMath::Lerp(GetActorRotation(), FRotator(0.f, Yaw, 0.f), RotationAlpha)); return GetActorRotation(); }
// Called when the game starts or when spawned void AInteractDoors::BeginPlay() { Super::BeginPlay(); bIsOpen = false; rotationClosed = GetActorRotation(); rotationOpen = GetActorRotation(); rotationOpen.Yaw += 90; }
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));*/ }
void AdeezProjectile::OnHit(UPrimitiveComponent* ThisComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit) { if ((OtherActor != NULL) && (OtherActor != this) && (OtherComp != NULL)) { // spawn FX AImpactFX* FX = GetWorld()->SpawnActorDeferred<AImpactFX>(ImpactTemplate, FTransform(Hit.Normal.Rotation(), Hit.Location), nullptr, Instigator, ESpawnActorCollisionHandlingMethod::AlwaysSpawn); if (FX) { FCollisionQueryParams Params = FCollisionQueryParams(FName(TEXT("RV_Trace")), true, this); Params.bTraceComplex = true; Params.bTraceAsyncScene = true; Params.bReturnPhysicalMaterial = true; FHitResult secondHit(ForceInit); FVector StartTrace; FVector EndTrace; StartTrace = GetActorLocation() - GetActorRotation().Vector() * 50; EndTrace = GetActorLocation() + GetActorRotation().Vector() * 200; GetWorld()->LineTraceSingleByChannel(secondHit, StartTrace, EndTrace, COLLISION_Weapon, Params); FPointDamageEvent PointDmg; //PointDmg.DamageTypeClass = DamageType; PointDmg.HitInfo = secondHit; PointDmg.ShotDirection = this->GetActorForwardVector(); PointDmg.Damage = Damage; if (this->GetOwner() && this->GetOwner()->GetInstigatorController()) { OtherActor->TakeDamage(Damage, PointDmg, this->GetOwner()->GetInstigatorController(), this->GetOwner()); } if (secondHit.bBlockingHit) { FX->SurfaceHit = secondHit; UGameplayStatics::FinishSpawningActor(FX, FTransform(FX->SurfaceHit.Normal.Rotation(), FX->SurfaceHit.Location)); } // simulate impact if (OtherComp->IsSimulatingPhysics()) { OtherComp->AddImpulseAtLocation(GetProjectileMovement()->Velocity * MassMultiplier, GetActorLocation()); } } } Destroy(); }
// Called every frame void AInteractDoors::Tick( float DeltaTime ) { Super::Tick( DeltaTime ); if (bIsOpen) { SetActorRotation(FMath::RInterpTo(GetActorRotation(), rotationOpen, DeltaTime, 5.f)); } else { SetActorRotation(FMath::RInterpTo(GetActorRotation(), rotationClosed, DeltaTime, 5.f)); } }
void APlayerShip::Tick(float DeltaTime) { // 회전 Super::Tick(DeltaTime); if (HandleStick->GetNormalizedFacingVector().IsZero()) { if (RotatorSize(CurrentRotationSpeed) > DeltaTime*RotationDeccelration) CurrentRotationSpeed -= DeltaTime*RotationDeccelration / (RotatorSize(CurrentRotationSpeed))*CurrentRotationSpeed; else CurrentRotationSpeed = FRotator::ZeroRotator; } else { TargetRotationSpeed = FRotator(-MaxRotationspeed*HandleStick->GetNormalizedFacingVector().X, MaxRotationspeed*HandleStick->GetNormalizedFacingVector().Y,0.0f); CurrentRotationSpeed += DeltaTime*RotationAcceleration / RotatorSize(TargetRotationSpeed - CurrentRotationSpeed)*(TargetRotationSpeed - CurrentRotationSpeed); //CurrentRotationSpeed += DeltaTime*RotationAcceleration*FRotator(-HandleStick->GetNormalizedFacingVector().X, HandleStick->GetNormalizedFacingVector().Y, 0); //if (RotatorSize(CurrentRotationSpeed) > MaxRotationspeed) // CurrentRotationSpeed = MaxRotationspeed / RotatorSize(CurrentRotationSpeed)*CurrentRotationSpeed; } if (GetActorRotation().Pitch > PitchClamper) CurrentRotationSpeed.Pitch = fmin(0, CurrentRotationSpeed.Pitch); if (GetActorRotation().Pitch < -PitchClamper) CurrentRotationSpeed.Pitch = fmax(0, CurrentRotationSpeed.Pitch); SetActorRotation(GetActorRotation() + DeltaTime*FRotator(CurrentRotationSpeed.Pitch, CurrentRotationSpeed.Yaw, 0)); //전진 //if (IsAccelerating) // CurrentSpeed += DeltaTime*Acceleration; //else // if (CurrentSpeed > DeltaTime*Decceleration) // CurrentSpeed -= DeltaTime*Decceleration; // else // CurrentSpeed = 0; // 전방방향 이동 // 엑셀 밟고 있을때 if (HandleStick->GetisPushingSecond()) { CurrentSpeed = (CurrentSpeed + DeltaTime*Acceleration > MaxSpeed) ? MaxSpeed : CurrentSpeed + DeltaTime*Acceleration; } else { CurrentSpeed = (CurrentSpeed - DeltaTime*Decceleration < 0) ? 0 : CurrentSpeed - DeltaTime*Decceleration; } AddActorLocalOffset(FVector(CurrentSpeed*DeltaTime, 0, 0)); //AddActorLocalRotation((DeltaTime*CurrentRotationSpeed).Quaternion()); //AddActorWorldRotation(FRotator(0,0,GetActorRotation().Roll)); //SetActorRotation(FRotator(GetActorRotation().Pitch, GetActorRotation().Yaw,0.0f)); //AddActorLocalRotation(FRotator(0,0, GetActorRotation().Roll)); }
// Called every frame void APawnWithCamera::Tick( float DeltaTime ) { Super::Tick( DeltaTime ); //zooming in and out code if (bZoomingIn) { ZoomFactor += DeltaTime / 0.5f; //zoom in over half a second } else { ZoomFactor -= DeltaTime / 0.25f; // zoom out over a quarter of a second } ZoomFactor = FMath::Clamp<float>(ZoomFactor, 0.0f, 1.0f); //blend our camera's FOV and our springArms length based on zoomfactor OurCamera->FieldOfView = FMath::Lerp<float>(90.0f, 60.0f, ZoomFactor); OurCameraSpringArm->TargetArmLength = FMath::Lerp<float>(400.0f, 300.0f, ZoomFactor); //camera control code { //rotate our actor's yaw which will turn our camera because we're attached to it FRotator newRot = GetActorRotation(); newRot.Yaw += CameraInput.X; SetActorRotation(newRot); //rotate the camera's pitch, but limit it so we're always looking downward FRotator newRot2 = OurCameraSpringArm->GetComponentRotation(); newRot2.Pitch = FMath::Clamp(newRot2.Pitch + CameraInput.Y, -80.0f, -15.0f); OurCameraSpringArm->SetWorldRotation(newRot2); FRotator newRot3 = OurCamera->GetComponentRotation(); newRot3.Roll = FMath::Lerp<float>(newRot.Roll, 120.0f * MovementInput.Y, DeltaTime); OurCamera->SetWorldRotation(newRot3); } //handle movememnt based on out movex and movey axes if (!MovementInput.IsZero()) { //scale our moevement input axis values by 100 units per second MovementInput = MovementInput.GetSafeNormal(); FVector newLoc = GetActorLocation(); newLoc += GetActorForwardVector() * MovementInput.X * DeltaTime * ForwardSpeed; newLoc += GetActorRightVector() * MovementInput.Y * DeltaTime * StrafeSpeed; SetActorLocation(newLoc); //also slightly roll the camera when the player strafes FRotator newRot = FRotator(GetActorRotation().Pitch, GetActorRotation().Yaw, 0.0f); newRot.Roll += MovementInput.Y * DeltaTime * StrafeSpeed; } }
void AActor::EditorApplyRotation(const FRotator& DeltaRotation, bool bAltDown, bool bShiftDown, bool bCtrlDown) { if( RootComponent != NULL ) { const FRotator Rot = RootComponent->GetAttachParent() != NULL ? GetActorRotation() : RootComponent->RelativeRotation; FRotator ActorRotWind, ActorRotRem; Rot.GetWindingAndRemainder(ActorRotWind, ActorRotRem); const FQuat ActorQ = ActorRotRem.Quaternion(); const FQuat DeltaQ = DeltaRotation.Quaternion(); const FQuat ResultQ = DeltaQ * ActorQ; const FRotator NewActorRotRem = FRotator( ResultQ ); FRotator DeltaRot = NewActorRotRem - ActorRotRem; DeltaRot.Normalize(); if( RootComponent->GetAttachParent() != NULL ) { RootComponent->SetWorldRotation( Rot + DeltaRot ); } else { // No attachment. Directly set relative rotation (to support winding) RootComponent->SetRelativeRotation( Rot + DeltaRot ); } } else { UE_LOG(LogActor, Warning, TEXT("WARNING: EditorApplyRotation %s has no root component"), *GetName() ); } }
bool ARobot::isObjectVisible(FVector objectPosition) { FVector ownLocation = GetActorLocation(); FRotator ownRotation = GetActorRotation(); float distance = sqrt(pow(ownLocation.X - objectPosition.X, 2) + pow(ownLocation.Y - objectPosition.X, 2)); if (distance < 500) //See everyting in a distance of 5 meter { return true; } //See everypting in the field of view float angle = FMath::RadiansToDegrees(atan2(ownLocation.Y - objectPosition.Y, ownLocation.X - objectPosition.X)); float deltaAngle = angle - ownRotation.Yaw + 180; if (deltaAngle < -180) deltaAngle += 360; { if (deltaAngle > 180) deltaAngle -= 360; { if (FMath::Abs(deltaAngle) <= HalfFieldOfView) { return true; } } } return false; }
void ANimModCharacter::PostInitializeComponents() { Super::PostInitializeComponents(); if (Role == ROLE_Authority) { Health = GetMaxHealth(); SpawnDefaultInventory(); } // set initial mesh visibility (3rd person view) UpdatePawnMeshes(); // create material instance for setting team colors (3rd person view) for (int32 iMat = 0; iMat < GetMesh()->GetNumMaterials(); iMat++) { MeshMIDs.Add(GetMesh()->CreateAndSetMaterialInstanceDynamic(iMat)); } // play respawn effects if (GetNetMode() != NM_DedicatedServer) { if (RespawnFX) { UGameplayStatics::SpawnEmitterAtLocation(this, RespawnFX, GetActorLocation(), GetActorRotation()); } if (RespawnSound) { UGameplayStatics::PlaySoundAtLocation(this, RespawnSound, GetActorLocation()); } } }
// Called every frame void ATheSwarmActor::Tick(float DeltaTime) { Super::Tick(DeltaTime); UCapsuleComponent* move = NULL; TArray<UCapsuleComponent*>comps; actor->GetComponents(comps); if (comps.Num() > 0) { move = comps[0]; } //adjust Z axis for allowing gravity FVector gravityFudge = FVector(GetActorLocation().X, GetActorLocation().Y, actor->GetActorLocation().Z); SetActorLocation(gravityFudge + velocity * DeltaTime); //moves swarm actor and child actor actor->SetActorLocation(GetActorLocation()); velocity = velocity.GetClampedToSize(0, 360); SetActorRotation(velocity.Rotation()); actor->SetActorRotation(GetActorRotation()); //allows animation assets to be used if (move != NULL) { move->SetAllPhysicsLinearVelocity(velocity); } }
void ACharacter::UpdateSimulatedPosition(const FVector & NewLocation, const FRotator & NewRotation) { // Always consider Location as changed if we were spawned this tick as in that case our replicated Location was set as part of spawning, before PreNetReceive() if( (NewLocation != GetActorLocation()) || (CreationTime == GetWorld()->TimeSeconds) ) { FVector FinalLocation = NewLocation; if( GetWorld()->EncroachingBlockingGeometry(this, NewLocation, NewRotation) ) { bSimGravityDisabled = true; } else { // Correction to make sure pawn doesn't penetrate floor after replication rounding FinalLocation.Z += 0.01f; bSimGravityDisabled = false; } // Don't use TeleportTo(), that clears our base. SetActorLocationAndRotation(FinalLocation, NewRotation, false); } else if( NewRotation != GetActorRotation() ) { GetRootComponent()->MoveComponent(FVector::ZeroVector, NewRotation, false); } }
void APawn::FaceRotation(FRotator NewControlRotation, float DeltaTime) { // Only if we actually are going to use any component of rotation. if (bUseControllerRotationPitch || bUseControllerRotationYaw || bUseControllerRotationRoll) { const FRotator CurrentRotation = GetActorRotation(); if (!bUseControllerRotationPitch) { NewControlRotation.Pitch = CurrentRotation.Pitch; } if (!bUseControllerRotationYaw) { NewControlRotation.Yaw = CurrentRotation.Yaw; } if (!bUseControllerRotationRoll) { NewControlRotation.Roll = CurrentRotation.Roll; } #if ENABLE_NAN_DIAGNOSTIC if (NewControlRotation.ContainsNaN()) { logOrEnsureNanError(TEXT("APawn::FaceRotation about to apply NaN-containing rotation to actor! New:(%s), Current:(%s)"), *NewControlRotation.ToString(), *CurrentRotation.ToString()); } #endif SetActorRotation(NewControlRotation); } }
void ABlinkAbility::StartAbility() { float ManaCost = 20; float CoolDown = 5; float curMana = owner->getMana(); if (curMana - ManaCost >= 0 && !(owner->getbCDBlink())) { owner->setMana(curMana - ManaCost); //owner->BlinkInCD(); bCoolDown = true; GetWorld()->GetTimerManager().SetTimer(CDHandle_Ability, this, &ABlinkAbility::callCoolDown, CoolDown); if (AbilitySound && AbilityFX) { UGameplayStatics::SpawnEmitterAtLocation(GetWorld(), AbilityFX, GetActorLocation()); UGameplayStatics::PlaySoundAttached(AbilitySound, owner->ShipMeshComponent); } FRotator curFacing = GetActorRotation(); FVector curLoc = GetActorLocation(); //get facing FVector destLoc = curLoc + curFacing.Vector() * 700; owner->TeleportTo(destLoc, curFacing); UGameplayStatics::SpawnEmitterAtLocation(GetWorld(), AbilityFX, GetActorLocation()); } }
// Called every frame void ASandShip::Tick( float DeltaTime ) { Super::Tick( DeltaTime ); if (Player == nullptr) { CapsuleComponent->SetPhysicsLinearVelocity(FVector::ZeroVector); return; } FRotator NewSpringArmRotation = SpringArm->GetComponentRotation(); NewSpringArmRotation.Pitch = FMath::Clamp(NewSpringArmRotation.Pitch + CameraInput.Y*DeltaTime*180.0f, -89.0f, 89.0f); NewSpringArmRotation.Yaw += CameraInput.X*DeltaTime*180.0f; SpringArm->SetWorldRotation(NewSpringArmRotation); MovementInput = MovementInput.GetClampedToSize(0.0f, 1.0f); FVector Forward = FVector::VectorPlaneProject(CapsuleComponent->GetForwardVector(), FVector::UpVector).GetSafeNormal(); FVector Right = FVector::VectorPlaneProject(CapsuleComponent->GetRightVector(), FVector::UpVector).GetSafeNormal(); //FHitResult groundtrace; //FCollisionShape traceshape = FCollisionShape::MakeSphere(CapsuleComponent->GetScaledCapsuleRadius()-5.0f); //FCollisionQueryParams gtparams; //gtparams.AddIgnoredActor(this); //GetWorld()->SweepSingleByChannel(groundtrace, GetActorLocation(), GetActorLocation() - 1000.0f*FVector::UpVector, FQuat::Identity, ECC_Visibility, traceshape, gtparams); //if (groundtrace.IsValidBlockingHit()) { // SetActorLocation(GetActorLocation()*FVector(1.0f, 1.0f, 0.0f) + FVector::UpVector*groundtrace.ImpactPoint.Z + FVector::UpVector*CapsuleComponent->GetScaledCapsuleHalfHeight(), false, nullptr, ETeleportType::TeleportPhysics); //} FVector Velocity2D = FVector::VectorPlaneProject(CapsuleComponent->GetPhysicsLinearVelocity(),FVector::UpVector); if (CurrentDrag > 1.0f) { MovementInput.Y = 0.0f; } FVector AdjustedMovementInput = MovementInput.Y * Forward; CapsuleComponent->AddForce(AdjustedMovementInput*PhysicsSettings.AccelRate,NAME_None,true); float mult = FMath::Lerp(FMath::Sqrt(Velocity2D.Size() / PhysicsSettings.MaxVelocity), Velocity2D.Size() / PhysicsSettings.MaxVelocity, Velocity2D.Size() / PhysicsSettings.MaxVelocity)* CurrentDrag; float tangent = FMath::Pow(1.0f - FMath::Abs(Velocity2D.GetSafeNormal() | Forward),0.25f); CapsuleComponent->AddForce(-Velocity2D.GetSafeNormal()*PhysicsSettings.AccelRate*mult, NAME_None, true); if (CurrentDrag == PhysicsSettings.CoastingDrag) { //Root->AddForce(Right.GetSafeNormal()*PhysicsSettings.AccelRate*MovementInput.X*mult/1.0f, NAME_None, true); } if (!MovementComponent->onground) { CapsuleComponent->AddForce(Player->PhysicsSettings.Gravity*FVector::UpVector, NAME_None, true); } CapsuleComponent->SetPhysicsLinearVelocity(Velocity2D.Size()*Forward*FMath::Sign(Velocity2D |Forward) + CapsuleComponent->GetPhysicsLinearVelocity().Z*FVector::UpVector); float thing = FMath::Lerp(FMath::Clamp(DeltaTime,0.0f,1.0f), 1.0f, FMath::Lerp((Velocity2D.Size() / PhysicsSettings.MaxVelocity)/2.0f,FMath::Pow(Velocity2D.Size() / PhysicsSettings.MaxVelocity, 8.0f), (Velocity2D.Size() / PhysicsSettings.MaxVelocity))); AdjustedTurnInput = FMath::Lerp(AdjustedTurnInput, MovementInput.X, DeltaTime); //CapsuleComponent->AddTorque(FVector::UpVector*MovementInput.X*PhysicsSettings.TurnRate*FMath::Clamp(1.4f - FMath::Pow(Velocity2D.Size() / PhysicsSettings.MaxVelocity, 1.5f),0.0f,1.0f), NAME_None, true); //CapsuleComponent->BodyInstance.bLockZRotation = false; MovementComponent->grounddetecttfudgefactor = FMath::Clamp(1.0f - FMath::Pow(Velocity2D.Size() / PhysicsSettings.MaxVelocity,0.5f),0.0f,1.0f); CapsuleComponent->SetWorldRotation(CapsuleComponent->GetComponentRotation() + FRotator(0.0, AdjustedTurnInput*PhysicsSettings.TurnRate *(1.1f - FMath::Pow(Velocity2D.Size() / PhysicsSettings.MaxVelocity, 1.5f))*DeltaTime,0.0f), NAME_None,nullptr, ETeleportType::TeleportPhysics); //CapsuleComponent->BodyInstance.bLockZRotation = true; Player->SetActorLocation(GetActorLocation() + 260.0f*FVector::UpVector, false, nullptr, ETeleportType::TeleportPhysics); Player->PlayerModel->SetWorldRotation(FRotator(0.0f, GetActorRotation().Yaw, 0.0f)); }
void AAmethystImpactEffect::PostInitializeComponents() { Super::PostInitializeComponents(); UPhysicalMaterial* HitPhysMat = SurfaceHit.PhysMaterial.Get(); EPhysicalSurface HitSurfaceType = UPhysicalMaterial::DetermineSurfaceType(HitPhysMat); // show particles UParticleSystem* ImpactFX = GetImpactFX(HitSurfaceType); if (ImpactFX) { UGameplayStatics::SpawnEmitterAtLocation(this, ImpactFX, GetActorLocation(), GetActorRotation()); } // play sound USoundCue* ImpactSound = GetImpactSound(HitSurfaceType); if (ImpactSound) { UGameplayStatics::PlaySoundAtLocation(this, ImpactSound, GetActorLocation()); } if (DefaultDecal.DecalMaterial) { FRotator RandomDecalRotation = SurfaceHit.ImpactNormal.Rotation(); RandomDecalRotation.Roll = FMath::FRandRange(-180.0f, 180.0f); UGameplayStatics::SpawnDecalAttached(DefaultDecal.DecalMaterial, FVector(DefaultDecal.DecalSize, DefaultDecal.DecalSize, 1.0f), SurfaceHit.Component.Get(), SurfaceHit.BoneName, SurfaceHit.ImpactPoint, RandomDecalRotation, EAttachLocation::KeepWorldPosition, DefaultDecal.LifeSpan); } }
void ACharacter::UpdateSimulatedPosition(const FVector& NewLocation, const FRotator& NewRotation) { // Always consider Location as changed if we were spawned this tick as in that case our replicated Location was set as part of spawning, before PreNetReceive() if( (NewLocation != GetActorLocation()) || (CreationTime == GetWorld()->TimeSeconds) ) { FVector FinalLocation = NewLocation; // Only need to check for encroachment when teleported without any velocity. // Normal movement pops the character out of geometry anyway, no use doing it before and after (with different rules). bSimGravityDisabled = false; if (CharacterMovement->Velocity.IsZero()) { if (GetWorld()->EncroachingBlockingGeometry(this, NewLocation, NewRotation)) { bSimGravityDisabled = true; } } // Don't use TeleportTo(), that clears our base. SetActorLocationAndRotation(FinalLocation, NewRotation, false); CharacterMovement->bJustTeleported = true; } else if( NewRotation != GetActorRotation() ) { GetRootComponent()->MoveComponent(FVector::ZeroVector, NewRotation, false); } }
// Called every frame void APawnWithCamera::Tick( float DeltaTime ) { Super::Tick( DeltaTime ); //Zoom in if ZoomIn button is down, zoom back out if it's not { if (bZoomingIn) { ZoomFactor += DeltaTime / 0.5f; //Zoom in over half a second } else { ZoomFactor -= DeltaTime / 0.25f; //Zoom out over a quarter of a second } ZoomFactor = FMath::Clamp<float>(ZoomFactor, 0.0f, 1.0f); //Blend our camera's FOV and our SpringArm's length based on ZoomFactor OurCamera->FieldOfView = FMath::Lerp<float>(90.0f, 60.0f, ZoomFactor); OurCameraSpringArm->TargetArmLength = FMath::Lerp<float>(400.0f, 300.0f, ZoomFactor); } //Rotate our actor's yaw, which will turn our camera because we're attached to it { FRotator NewRotation = GetActorRotation(); NewRotation.Yaw += CameraInput.X; SetActorRotation(NewRotation); } //Rotate our camera's pitch, but limit it so we're always looking downward { FRotator NewRotation = OurCameraSpringArm->GetComponentRotation(); NewRotation.Pitch = FMath::Clamp(NewRotation.Pitch + CameraInput.Y, -80.0f, -15.0f); OurCameraSpringArm->SetWorldRotation(NewRotation); } }
bool APawn::ReachedDesiredRotation() { // Only base success on Yaw FRotator DesiredRotation = Controller ? Controller->GetDesiredRotation() : GetActorRotation(); float YawDiff = FMath::Abs(FRotator::ClampAxis(DesiredRotation.Yaw) - FRotator::ClampAxis(GetActorRotation().Yaw)); return ( (YawDiff < AllowedYawError) || (YawDiff > 360.f - AllowedYawError) ); }
void ABrainCharacter::LookUp(float value) { FRotator actorRotation = GetActorRotation(); actorRotation.Pitch += value; LimitPitch(actorRotation, _minPitch, _maxPitch); SetActorRotation(actorRotation); }
void UMyAnimInstance::NativeUpdateAnimation(float DeltaSeconds) { Super::NativeUpdateAnimation(DeltaSeconds); const auto PawnOwner = TryGetPawnOwner(); if (nullptr != PawnOwner) { //!< スピード const auto Velocity = PawnOwner->GetVelocity(); Speed = Velocity.Size(); //!< 方向 Direction = (Velocity.Rotation() - PawnOwner->GetActorRotation()).Yaw; while (Direction < -180.0f) { Direction += 360.0f; } while (Direction > 180.0f) { Direction -= 360.0f; } //!< 落下 const auto MovementComp = PawnOwner->GetMovementComponent(); if (nullptr != MovementComp) { IsFalling = MovementComp->IsFalling(); } } }
void ACloud10Character::MoveForward(float Value) { if (isDiving) { float prevPitch = GetActorRotation().Pitch; float minDeltaPitch = minPitch - prevPitch; float maxDeltaPitch = maxPitch - prevPitch; //roll character in an angle front and back float curPitchAmt = Value; FRotator dRotation(0,0,0); dRotation.Pitch = FMath::ClampAngle(curPitchAmt * rotationRate, minDeltaPitch, maxDeltaPitch); AddActorLocalRotation(dRotation); } else { if ((Controller != NULL) && (Value != 0.0f)) { // find out which way is forward const FRotator Rotation = Controller->GetControlRotation(); const FRotator YawRotation(0, Rotation.Yaw, 0); // get forward vector const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X); AddMovementInput(Direction, Value); } } }
void ASeaCraftExplosionEffect::BeginPlay() { Super::BeginPlay(); if (ExplosionFX) { UGameplayStatics::SpawnEmitterAtLocation(this, ExplosionFX, GetActorLocation(), GetActorRotation()); } if (ExplosionSound) { UGameplayStatics::PlaySoundAtLocation(this, ExplosionSound, GetActorLocation()); } if (Decal.DecalMaterial) { FRotator RandomDecalRotation = SurfaceHit.ImpactNormal.Rotation(); RandomDecalRotation.Roll = FMath::FRandRange(-180.0f, 180.0f); UGameplayStatics::SpawnDecalAttached(Decal.DecalMaterial, FVector(Decal.DecalSize, Decal.DecalSize, 1.0f), SurfaceHit.Component.Get(), SurfaceHit.BoneName, SurfaceHit.ImpactPoint, RandomDecalRotation, EAttachLocation::KeepWorldPosition, Decal.LifeSpan); } }
void ANavigationObjectBase::Validate() { if ( ShouldBeBased() && (GoodSprite || BadSprite) ) { FVector OrigLocation = GetActorLocation(); const float Radius = CapsuleComponent->GetScaledCapsuleRadius(); FVector const Slice(Radius, Radius, 1.f); bool bResult = true; // Check for adjustment FHitResult Hit(ForceInit); const FVector TraceStart = GetActorLocation(); const FVector TraceEnd = GetActorLocation() - FVector(0.f,0.f, 4.f * CapsuleComponent->GetScaledCapsuleHalfHeight()); GetWorld()->SweepSingleByChannel(Hit, TraceStart, TraceEnd, FQuat::Identity, ECC_Pawn, FCollisionShape::MakeBox(Slice), FCollisionQueryParams(NAME_None, false, this)); if( Hit.bBlockingHit ) { const FVector HitLocation = TraceStart + (TraceEnd - TraceStart) * Hit.Time; FVector Dest = HitLocation + FVector(0.f,0.f,CapsuleComponent->GetScaledCapsuleHalfHeight()-2.f); // Move actor (TEST ONLY) to see if navigation point moves TeleportTo( Dest, GetActorRotation(), false, true ); // If only adjustment was down towards the floor, then it is a valid placement FVector NewLocation = GetActorLocation(); bResult = ( NewLocation.X == OrigLocation.X && NewLocation.Y == OrigLocation.Y && NewLocation.Z <= OrigLocation.Z ); // Move actor back to original position TeleportTo( OrigLocation, GetActorRotation(), false, true ); } // Update sprites by result if( GoodSprite ) { GoodSprite->SetVisibility(bResult); } if( BadSprite ) { BadSprite->SetVisibility(!bResult); } } // Force update of icon MarkComponentsRenderStateDirty(); }
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; } } } } } }