当前位置: 首页>>代码示例>>C++>>正文


C++ Transform::GetGlobalPosition方法代码示例

本文整理汇总了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;
	}
}
开发者ID:Benjins,项目名称:BNGine,代码行数:77,代码来源:EnemyComponent.cpp


注:本文中的Transform::GetGlobalPosition方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。