public EnemyState GetEnemyState() { if (_enemyHealth.isDead) { lastState.health = 0; return(lastState); } var rigidBodyTransform = _enemyMovement.rigidbody.transform; var position = rigidBodyTransform.position; var rotation = rigidBodyTransform.rotation.eulerAngles; var health = _enemyHealth.currentHealth; var enemyState = new EnemyState(id, position.x, position.y, position.z, rotation.x, rotation.y, rotation.z, health, type); var hitPoint = _enemyHealth.hitPoint; enemyState.AddHitPoint(hitPoint.x, hitPoint.y, hitPoint.z); lastState = enemyState; return(enemyState); }
private void interpolateEnemies(float interpolationTime, Snapshot interpolatedSnapshot) { var fromEnemies = _fromSnapshot.enemies; var toEnemies = _toSnapshot.enemies; var amountOfEnemies = fromEnemies.Count; for (var i = 0; i < amountOfEnemies; i++) { EnemyState fromEnemy = fromEnemies[i]; EnemyState toEnemy; if (toEnemies.Count > i) { toEnemy = toEnemies[i]; } else { toEnemy = fromEnemy; } var fromVector = new Vector3(fromEnemy.x, fromEnemy.y, fromEnemy.z); var toVector = new Vector3(toEnemy.x, toEnemy.y, toEnemy.z); var n = (interpolationTime - _fromTime) / (_toTime - _fromTime); var vector = Vector3.Lerp(fromVector, toVector, n); var fromRotateVector = new Vector3(fromEnemy.xA, fromEnemy.yA, fromEnemy.zA); var toRotateVector = new Vector3(toEnemy.xA, toEnemy.yA, toEnemy.zA); var rotation = Vector3.Lerp(fromRotateVector, toRotateVector, n); var state = new EnemyState(fromEnemy.id, vector.x, vector.y, vector.z, rotation.x, rotation.y, rotation.z, fromEnemy.health, fromEnemy.type ); state.AddHitPoint(fromEnemy.xH, fromEnemy.yH, fromEnemy.zH); interpolatedSnapshot.enemies.Add(state); } }