本文整理汇总了C++中UPrimitiveComponent::SetPhysicsAngularVelocity方法的典型用法代码示例。如果您正苦于以下问题:C++ UPrimitiveComponent::SetPhysicsAngularVelocity方法的具体用法?C++ UPrimitiveComponent::SetPhysicsAngularVelocity怎么用?C++ UPrimitiveComponent::SetPhysicsAngularVelocity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UPrimitiveComponent
的用法示例。
在下文中一共展示了UPrimitiveComponent::SetPhysicsAngularVelocity方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: KickToLocation
/** Kicks this ball to a location */
void AMagicBattleSoccerBall::KickToLocation(const FVector& Location, float AngleInDegrees)
{
if (nullptr == Possessor)
{
// Safety check. The possessor must be valid.
}
else
{
// Reset the possessor
SetPossessor(nullptr);
// Calculate the angle required to hit the coordinate (x,y) on the plane containing
// the origin and ground point. The x coordinate is the distance from the ball
// to where the user clicked, and the y coordinate should be zero.
// http://en.wikipedia.org/wiki/Trajectory_of_a_projectile
FVector Origin = GetActorLocation();
float x = FVector::Dist(Location, Origin);
float y = 0.f;
float g = -980.f; // Standard gravity
float r = AngleInDegrees * 3.14159f / 180.f;
float p = std::tan(r);
float v = std::sqrt((p*p + 1.f)*(g*x*x) / (2.f * (y - x*p)));
float forceMag = v;
FVector forward = (Location - Origin);
forward.Z = 0; // We only support kicking to locations that are on the ball's Z plane
forward.Normalize();
FVector cross = FVector::CrossProduct(forward, FVector::UpVector);
FVector kick = forward * FMath::Cos(r) * forceMag;
kick.Z = FMath::Sin(r) * forceMag;
UPrimitiveComponent *Root = Cast<UPrimitiveComponent>(GetRootComponent());
Root->SetPhysicsLinearVelocity(kick);
Root->SetPhysicsAngularVelocity(cross * forceMag * -4.f);
}
}
示例2: LoadSpacecraft
AFlareSpacecraft* UFlareSector::LoadSpacecraft(UFlareSimulatedSpacecraft* ParentSpacecraft)
{
AFlareSpacecraft* Spacecraft = NULL;
FLOGV("UFlareSector::LoadSpacecraft : Start loading ('%s')", *ParentSpacecraft->GetImmatriculation().ToString());
// Spawn parameters
FActorSpawnParameters Params;
Params.bNoFail = true;
Params.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AdjustIfPossibleButAlwaysSpawn;
// Create and configure the ship
Spacecraft = GetGame()->GetWorld()->SpawnActor<AFlareSpacecraft>(ParentSpacecraft->GetDescription()->Template->GeneratedClass, ParentSpacecraft->GetData().Location, ParentSpacecraft->GetData().Rotation, Params);
if (Spacecraft && !Spacecraft->IsPendingKillPending())
{
Spacecraft->Load(ParentSpacecraft);
UPrimitiveComponent* RootComponent = Cast<UPrimitiveComponent>(Spacecraft->GetRootComponent());
if (Spacecraft->IsStation())
{
SectorStations.Add(Spacecraft);
}
else
{
SectorShips.Add(Spacecraft);
}
SectorSpacecrafts.Add(Spacecraft);
FLOGV("%s spawn mode = %d", *Spacecraft->GetImmatriculation().ToString(), ParentSpacecraft->GetData().SpawnMode+0)
switch (ParentSpacecraft->GetData().SpawnMode)
{
// Already known to be correct
case EFlareSpawnMode::Safe:
FLOGV("UFlareSector::LoadSpacecraft : Safe spawn '%s' at (%f,%f,%f)",
*ParentSpacecraft->GetImmatriculation().ToString(),
ParentSpacecraft->GetData().Location.X, ParentSpacecraft->GetData().Location.Y, ParentSpacecraft->GetData().Location.Z);
RootComponent->SetPhysicsLinearVelocity(ParentSpacecraft->GetData().LinearVelocity, false);
RootComponent->SetPhysicsAngularVelocity(ParentSpacecraft->GetData().AngularVelocity, false);
break;
// First spawn
case EFlareSpawnMode::Spawn:
PlaceSpacecraft(Spacecraft, ParentSpacecraft->GetData().Location);
{
FVector NewLocation = Spacecraft->GetActorLocation();
FLOGV("UFlareSector::LoadSpacecraft : Placing '%s' at (%f,%f,%f)",
*ParentSpacecraft->GetImmatriculation().ToString(),
NewLocation.X, NewLocation.Y, NewLocation.Z);
}
RootComponent->SetPhysicsLinearVelocity(FVector::ZeroVector, false);
RootComponent->SetPhysicsAngularVelocity(FVector::ZeroVector, false);
break;
// Incoming in sector
case EFlareSpawnMode::Travel:
{
FLOGV("UFlareSector::LoadSpacecraft : Travel '%s' at (%f, %f, %f)",
*ParentSpacecraft->GetImmatriculation().ToString(),
ParentSpacecraft->GetData().Location.X, ParentSpacecraft->GetData().Location.Y, ParentSpacecraft->GetData().Location.Z);
FVector SpawnDirection;
TArray<AFlareSpacecraft*> FriendlySpacecrafts = GetCompanySpacecrafts(Spacecraft->GetCompany());
FVector FriendlyShipLocationSum = FVector::ZeroVector;
int FriendlyShipCount = 0;
for (int SpacecraftIndex = 0 ; SpacecraftIndex < FriendlySpacecrafts.Num(); SpacecraftIndex++)
{
AFlareSpacecraft *SpacecraftCandidate = FriendlySpacecrafts[SpacecraftIndex];
if (!SpacecraftCandidate->IsStation() && SpacecraftCandidate != Spacecraft)
{
FriendlyShipLocationSum += SpacecraftCandidate->GetActorLocation();
FriendlyShipCount++;
}
}
if (FriendlyShipCount == 0)
{
FVector NotFriendlyShipLocationSum = FVector::ZeroVector;
int NotFriendlyShipCount = 0;
for (int SpacecraftIndex = 0 ; SpacecraftIndex < SectorShips.Num(); SpacecraftIndex++)
{
AFlareSpacecraft *SpacecraftCandidate = SectorShips[SpacecraftIndex];
if (SpacecraftCandidate != Spacecraft && SpacecraftCandidate->GetCompany() != Spacecraft->GetCompany())
{
NotFriendlyShipLocationSum += SpacecraftCandidate->GetActorLocation();
NotFriendlyShipCount++;
}
}
if (NotFriendlyShipCount == 0)
{
//.........这里部分代码省略.........