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 UPrimitiveComponent::SetAllPhysicsLinearVelocity(FVector NewVel,bool bAddToCurrent) { SetPhysicsLinearVelocity(NewVel, bAddToCurrent, NAME_None); }