void navigateMissile(Entity e, HomeMissileComponent homeMissile) { FollowTargetComponent targetComponent = e.followTarget; // The target is not alive, so go find another one. if (targetComponent.target == null || !targetComponent.target.hasGameObject) { e.AddFindTarget(homeMissile.targetCollisionType); e.RemoveFollowTarget(); return; } setMissileVelocity(e, homeMissile, targetComponent); }
void setMissileVelocity(Entity e, HomeMissileComponent homeMissile, FollowTargetComponent targetComponent) { Entity targetEntity = targetComponent.target; Vector2 position = e.position.pos; Vector2 targetPosition = targetEntity.position.pos; VelocityComponent velocity = e.velocity; tempVector.Set((targetPosition.x - position.x), (targetPosition.y - position.y)); tempVector.Normalize(); tempVector *= homeMissile.speed; tempVector -= velocity.vel; tempVector *= Kp; velocity.vel += tempVector; }