本文整理汇总了C++中Transform::GetGlobalPosition方法的典型用法代码示例。如果您正苦于以下问题:C++ Transform::GetGlobalPosition方法的具体用法?C++ Transform::GetGlobalPosition怎么用?C++ Transform::GetGlobalPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Transform
的用法示例。
在下文中一共展示了Transform::GetGlobalPosition方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Update
void EnemyComponent::Update() {
if (playerId.id == 0xFFFFFFFF) {
playerId = GlobalScene->gameplay.players.vals[0].entity;
}
if (!hasCalculatedPatrolPoints) {
patrolPoints.EnsureCapacity(GlobalScene->gameplay.patrolPoints.currentCount);
for (int i = 0; i < GlobalScene->gameplay.patrolPoints.currentCount; i++) {
patrolPoints.PushBack(GlobalScene->gameplay.patrolPoints.vals[i].entity);
}
ASSERT_MSG(patrolPoints.count > 0, "Must have patrol points if have an enemy in scene %d", GlobalScene->currentLevel)
hasCalculatedPatrolPoints = true;
}
Transform* trans = GlobalScene->transforms.GetById(GlobalScene->entities.GetById(entity)->transform);
HealthComponent* health = FIND_COMPONENT_BY_ENTITY(HealthComponent, entity);
if (health->IsDead()) {
GlobalScene->DestroyEntity(entity);
}
const float enemyHeight = 1.5f;
float floorHeight = -10.0f;
// TODO: Copied from player code, pull out to common function?
if (enemydoDownCast) {
RaycastHit downCast = GlobalScene->phys.Raycast(trans->GetGlobalPosition() + Vector3(0, 0.5f, 0), Y_AXIS * -1);
if (downCast.wasHit) {
floorHeight = downCast.globalPos.y;
}
}
switch (currentState) {
case ES_Patrol: {
Entity* goalEnt = GlobalScene->entities.GetById(patrolPoints.data[patrolIndex]);
Vector3 goal = GlobalScene->transforms.GetById(goalEnt->transform)->GetGlobalPosition();
Vector3 toGoal = goal - trans->GetGlobalPosition();
if (Vector2(toGoal.x, toGoal.z).Magnitude() < 0.2f){
patrolIndex = (patrolIndex + 1) % patrolPoints.count;
currentState = ES_Paused;
timer = 0;
}
else {
Vector3 moveVec = toGoal.Normalized() * GlobalScene->GetDeltaTime() * speed;
trans->position = trans->position + moveVec;
if (enemydoDownCast) {
trans->position.y = floorHeight;
}
}
} break;
case ES_Paused: {
timer += GlobalScene->GetDeltaTime();
if (timer > pauseTime) {
currentState = ES_Patrol;
timer = 0;
}
} break;
case ES_Chase: {
} break;
case ES_AttackWait: {
} break;
case ES_Attack: {
} break;
}
}