void UTankTrack::ApplySidewaysForce() { // Workout the required acceleration this frame to correct auto SlippageSpeed = FVector::DotProduct(GetRightVector(), GetComponentVelocity()); auto DeltaTime = GetWorld()->GetDeltaSeconds(); auto CorrectionAcceleration = -SlippageSpeed / DeltaTime * GetRightVector(); // Calculate and apply sideways force ( F = ma ) auto TankRoot = Cast<UStaticMeshComponent>(GetOwner()->GetRootComponent()); auto CorrectionForce = (TankRoot->GetMass() * CorrectionAcceleration) / 2; // Two tracks TankRoot->AddForce(CorrectionForce); }
///--------------------------------------------------------------------------------- /// ///--------------------------------------------------------------------------------- inline const Vector3 Camera3D::GetUpVector() const { Vector3 cameraUp = CrossProduct( GetRightVector(), GetForwardVector() ); cameraUp.Normalize(); return cameraUp; }
Vector Matrix4x4::GetScale() const { Vector vecReturn; vecReturn.x = GetForwardVector().Length(); vecReturn.y = GetUpVector().Length(); vecReturn.z = GetRightVector().Length(); return vecReturn; }
// Use the information embedded in a matrix to create its inverse. // http://youtu.be/7CxKAtWqHC8 Matrix4x4 Matrix4x4::InvertedTR() const { // This method can only be used if the matrix is a translation/rotation matrix. // The below asserts will trigger if this is not the case. TAssert(fabs(GetForwardVector().LengthSqr() - 1) < 0.00001f); // Each basis vector should be length 1. TAssert(fabs(GetUpVector().LengthSqr() - 1) < 0.00001f); TAssert(fabs(GetRightVector().LengthSqr() - 1) < 0.00001f); TAssert(fabs(GetForwardVector().Dot(GetUpVector())) < 0.0001f); // All vectors should be orthogonal. TAssert(fabs(GetForwardVector().Dot(GetRightVector())) < 0.0001f); TAssert(fabs(GetRightVector().Dot(GetUpVector())) < 0.0001f); Matrix4x4 M; // Create the transposed upper 3x3 matrix for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) M.m[i][j] = m[j][i]; // The new matrix translation = -Rt M.SetTranslation(-(M*GetTranslation())); return M; }
void UTankTrack::ApplySidewaysForce() { if (ensure(TankRoot)) { FVector RightVector = GetRightVector(); float DeltaTime = GetWorld()->GetDeltaSeconds(); // Calculate the slippage speed float SlippageSpeed = FVector::DotProduct(RightVector, GetComponentVelocity()); // Work-out the required acceleration this frame to correct FVector CorrectionAcceleration = -SlippageSpeed / DeltaTime * RightVector; // Calculate and apply sideways for ( F = m a) FVector CorrectionForce = (TankRoot->GetMass() * CorrectionAcceleration) / 2.f; // Two Tracks TankRoot->AddForce(CorrectionForce); } }
void Player::AttackAnimationTimerFinished() { if (IsBow()) { } else if (IsBoomerang()) { vec3 boomerangSpawnPosition = GetCenter() + (m_forward*0.75f) + (GetRightVector()*-0.4f) + (GetUpVector()*0.5f); float cameraModification = (m_cameraForward.y*17.5f); if (m_cameraForward.y < 0.0f) { cameraModification = (m_cameraForward.y*5.0f); } vec3 boomerangTarget = boomerangSpawnPosition + m_forward*15.0f + (vec3(0.0f, 1.0f, 0.0f) * cameraModification); if (m_pTargetEnemy != NULL) { boomerangTarget = m_pTargetEnemy->GetProjectileHitboxCenter(); if (m_pTargetEnemy->IsMoving()) { boomerangTarget += m_pTargetEnemy->GetForwardVector() * (m_pTargetEnemy->GetMovementSpeed() / 3.0f); } } float curveTime = length(boomerangTarget - boomerangSpawnPosition) / 15.0f; if (curveTime <= 0.4f) curveTime = 0.4f; Projectile* pProjectile = m_pProjectileManager->CreateProjectile(boomerangSpawnPosition, vec3(0.0f, 0.0f, 0.0f), 0.0f, "media/gamedata/weapons/Boomerang/BoomerangThrown.weapon", 0.05f); pProjectile->SetProjectileType(true, false, false); pProjectile->SetOwner(this, NULL, NULL); pProjectile->SetGravityMultiplier(0.0f); pProjectile->SetReturnToPlayer(true); pProjectile->SetProjectileCurveParams(m_forward, boomerangTarget, curveTime); pProjectile->SetWorldCollisionEnabled(true); m_pVoxelCharacter->SetRenderRightWeapon(false); } else if (IsStaff()) { float powerAmount = 25.0f; float cameraMultiplier = 25.0f; vec3 spellSpawnPosition = GetCenter() + (m_forward*1.25f) + (GetUpVector()*0.25f); if (VoxGame::GetInstance()->GetCameraMode() == CameraMode_FirstPerson) { cameraMultiplier = 30.0f; spellSpawnPosition.y += 0.75f; } vec3 spellSpawnVelocity = m_forward * powerAmount + vec3(0.0f, 1.0f, 0.0f) * (m_cameraForward.y*cameraMultiplier); if (m_pTargetEnemy != NULL) { vec3 toTarget = m_pTargetEnemy->GetProjectileHitboxCenter() - GetCenter(); spellSpawnVelocity = (normalize(toTarget) * powerAmount); } Projectile* pProjectile = m_pProjectileManager->CreateProjectile(spellSpawnPosition, spellSpawnVelocity, 0.0f, "media/gamedata/items/Fireball/Fireball.item", 0.05f); pProjectile->SetProjectileType(true, false, false); pProjectile->SetOwner(this, NULL, NULL); pProjectile->SetGravityMultiplier(0.0f); } else if (IsWand()) { } else if (IsBomb()) { vec3 bombSpawnPosition = GetCenter() + (m_forward*0.75f) + (GetUpVector()*0.5f); float liftAmount = 8.0f; float powerAmount = 30.0f; float cameraMultiplier = 25.0f; if (VoxGame::GetInstance()->GetCameraMode() == CameraMode_FirstPerson) { cameraMultiplier = 30.0f; } vec3 bombSpawnVelocity; if (m_pTargetEnemy) { // Enemy target vec3 toTarget = m_pTargetEnemy->GetCenter() - GetCenter(); float toTargetDistance = length(toTarget); liftAmount += toTargetDistance * 0.04f; bombSpawnVelocity = (normalize(toTarget) * powerAmount) + vec3(0.0f, liftAmount, 0.0f); } else { bombSpawnVelocity = (m_forward * powerAmount) + (GetUpVector() * liftAmount) + vec3(0.0f, 1.0f, 0.0f) * (m_cameraForward.y*cameraMultiplier); } Projectile* pProjectile = m_pProjectileManager->CreateProjectile(bombSpawnPosition, bombSpawnVelocity, 0.0f, "media/gamedata/items/Bomb/BombThrown.item", 0.05f); pProjectile->SetProjectileType(true, false, false); pProjectile->SetOwner(this, NULL, NULL); pProjectile->SetGravityMultiplier(3.5f); float explodeRadius = 3.5f - (GetRandomNumber(-150, 0, 2) * 0.01f); pProjectile->SetExplodingProjectile(true, explodeRadius); //m_pVoxelCharacter->SetRenderRightWeapon(false); InventoryItem* pItem = m_pInventoryManager->GetInventoryItemForEquipSlot(EquipSlot_RightHand); if (pItem != NULL) { if (pItem->m_quantity != -1) { pItem->m_quantity -= 1; } if (pItem->m_quantity == 0) { // Remove this item from the manager, and remove it from the inventory and GUI UnequipItem(EquipSlot_RightHand, false, false); m_pInventoryManager->RemoveInventoryItem(EquipSlot_RightHand); m_pActionBar->RemoveInventoryItemFromActionBar(pItem->m_title); } } } else if (IsConsumable()) { } else if (IsDagger()) { } else if (IsHammer()) { } else if (IsMace()) { } else if (IsSickle()) { } else if (IsPickaxe()) { Item* pInteractItem = VoxGame::GetInstance()->GetInteractItem(); if (pInteractItem != NULL) { pInteractItem->Interact(); } else { DestroyBlock(); } } else if (IsAxe()) { } else if (Is2HandedSword()) { } else if (IsSword()) { } else if (IsBlockPlacing()) { } else if (IsItemPlacing()) { } else if (IsSceneryPlacing()) { } else if (IsSpellHands()) { float powerAmount = 25.0f; float cameraMultiplier = 25.0f; vec3 spellSpawnPosition = GetCenter() + (m_forward*0.5f) + (GetUpVector()*0.0f); // For right hand spellSpawnPosition += -(GetRightVector()*0.4f); if (VoxGame::GetInstance()->GetCameraMode() == CameraMode_FirstPerson) { cameraMultiplier = 30.0f; spellSpawnPosition.y += 0.75f; } vec3 spellSpawnVelocity = m_forward * powerAmount + vec3(0.0f, 1.0f, 0.0f) * (m_cameraForward.y*cameraMultiplier); if (m_pTargetEnemy != NULL) { vec3 toTarget = m_pTargetEnemy->GetProjectileHitboxCenter() - GetCenter(); spellSpawnVelocity = (normalize(toTarget) * powerAmount); } Projectile* pProjectile = m_pProjectileManager->CreateProjectile(spellSpawnPosition, spellSpawnVelocity, 0.0f, "media/gamedata/items/Fireball/FireballBlue.item", 0.05f); pProjectile->SetProjectileType(true, false, false); pProjectile->SetOwner(this, NULL, NULL); pProjectile->SetGravityMultiplier(0.0f); } else if (IsShield()) { } else if (IsTorch()) { } }
void Player::AttackAnimationTimerFinished_Alternative() { if (IsBow()) { } else if (IsBoomerang()) { } else if (IsStaff()) { } else if (IsWand()) { } else if (IsBomb()) { } else if (IsConsumable()) { } else if (IsDagger()) { } else if (IsHammer()) { } else if (IsMace()) { } else if (IsSickle()) { } else if (IsPickaxe()) { } else if (IsAxe()) { } else if (Is2HandedSword()) { } else if (IsSword()) { } else if (IsBlockPlacing()) { } else if (IsItemPlacing()) { } else if (IsSceneryPlacing()) { } else if (IsSpellHands()) { float powerAmount = 25.0f; float cameraMultiplier = 25.0f; vec3 spellSpawnPosition = GetCenter() + (m_forward*0.5f) + (GetUpVector()*0.0f); // For left hand spellSpawnPosition += (GetRightVector()*0.4f); if (VoxGame::GetInstance()->GetCameraMode() == CameraMode_FirstPerson) { cameraMultiplier = 30.0f; spellSpawnPosition.y += 0.75f; } vec3 spellSpawnVelocity = m_forward * powerAmount + vec3(0.0f, 1.0f, 0.0f) * (m_cameraForward.y*cameraMultiplier); if (m_pTargetEnemy != NULL) { vec3 toTarget = m_pTargetEnemy->GetProjectileHitboxCenter() - GetCenter(); spellSpawnVelocity = (normalize(toTarget) * powerAmount); } Projectile* pProjectile = m_pProjectileManager->CreateProjectile(spellSpawnPosition, spellSpawnVelocity, 0.0f, "media/gamedata/items/Fireball/FireballBlue.item", 0.05f); pProjectile->SetProjectileType(true, false, false); pProjectile->SetOwner(this, NULL, NULL); pProjectile->SetGravityMultiplier(0.0f); } else if (IsShield()) { } else if (IsTorch()) { } }