qqwref

Uno Mas: Homing

Apr 13th, 2020 (edited)
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. /* Uno Mas: Homing */
  2.  
  3. platform3D(-25, -25, 0, 70, 70, 1, color(82, 255, 82));
  4.  
  5. function homingEnemy(x, y, z, id, speed) {
  6. if (!"homingEnemies" in player || player["homingEnemies"] === undefined) {
  7. player["homingEnemies"] = {};
  8. }
  9. if (!id in player["homingEnemies"] || player["homingEnemies"][id] === undefined) {
  10. player["homingEnemies"][id] = [x, y, z];
  11. } else {
  12. currentLocation = player["homingEnemies"][id];
  13. var direction = [player.pos[0] - currentLocation[0], player.pos[1] - currentLocation[1], player.pos[2] - currentLocation[2]];
  14. var normal = Math.sqrt(direction[0] * direction[0] + direction[1] * direction[1] + direction[2] * direction[2]);
  15. newLocation = [currentLocation[0] + speed * direction[0] / normal, currentLocation[1] + speed * direction[1] / normal, currentLocation[2] + speed * direction[2] / normal];
  16. player["homingEnemies"][id] = newLocation;
  17. }
  18. platform3D(player["homingEnemies"][id][0] - 1, player["homingEnemies"][id][1] - 1, player["homingEnemies"][id][2] - 1, 2, 2, 2, color(0, 0, 0));
  19. if (isColliding(player.pos[0] - player.size[0], player.pos[1] - player.size[1], player.pos[2] - player.size[2], player.size[0] * 2, player.size[1] * 2, player.size[2] * 2, player["homingEnemies"][id][0] - 1, player["homingEnemies"][id][1] - 1, player["homingEnemies"][id][2] - 1, 2, 2, 2)) {
  20. player.pos[2] = 10;
  21. }
  22. if (player.pos[0] == player.respawnPos[0] && player.pos[1] == player.respawnPos[1] && player.pos[2] == player.respawnPos[2]) {
  23. player["homingEnemies"][id] = undefined;
  24. }
  25. }
  26.  
  27. homingEnemy(30, 30, -30, "W", 0.2);
  28. homingEnemy(-30, 30, -30, "X", 0.2);
  29. homingEnemy(-30, -30, -30, "Y", 0.2);
  30. homingEnemy(30, -30, -30, "Z", 0.2);
  31.  
  32. platform3D(10, 10, -2, 15, 15, 1, color(255, 82, 82));
  33. platform3D(-15, -20, -8, 10, 15, 3, color(82, 255, 255));
  34.  
  35.  
  36.  
  37. addCheckpoint(15, 20, -1);
  38. addCoin(-10, 20, -1);
Advertisement
Add Comment
Please, Sign In to add comment