Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //remember to set these global variables for easy adjustment
- let SHOT_HOMING = /*how strong the homing on the shots should be*/
- let SHOT_MAX_HOMING_DIST = /*the shot will home in on enemies within this distance*/
- //you also need this function
- function angleTo(obj,dest) {
- let dir = atan2(ObjMove_GetY(dest)-ObjMove_GetY(obj),ObjMove_GetX(dest)-ObjMove_GetX(obj));
- return dir;
- }
- //whenever you need to fire a homing shot just use this section
- let bullet = CreatePlayerShotA1(input desired values);
- shotCommands(bullet);
- //----------------------------
- //insert this somewhere else, probably near the bottom
- task shotCommands(obj) {
- //A:
- while (!Obj_IsDeleted(obj)) {
- //1:
- let enemyMatrix = GetIntersectionRegistedEnemyID;
- //2:
- let homingBool = false;
- //3:
- if (length(enemyMatrix) > 0) {
- //3.1:
- let targetDist = SHOT_MAX_HOMING_DIST;
- //3.2:
- let targetID = 0;
- //3.3:
- ascent (i in 0..length(enemyMatrix)) {
- //3.3.1:
- if (GetObjectDistance(obj,enemy[i]) < targetDist) {
- //3.3.1.1:
- targetDist = GetObjectDistance(obj,enemy[i]);
- //3.3.1.2:
- targetID = enemyMatrix[i];
- //3.3.1.3:
- homingBool = true;
- }
- }
- //3.4:
- if (homingBool == true) {
- //3.4.1:
- let shotAngle = ObjMove_GetAngle(obj);
- //3.4.1.1:
- while (shotAngle >= 360) {
- shotAngle -= 360;
- }
- while (shotAngle < 0) {
- shotAngle += 360;
- }
- //3.4.2:
- let targetAngle = angleTo(obj,target);
- //3.4.2.1:
- while (targetAngle >= 360) {
- targetAngle -= 360;
- }
- while (targetAngle < 0) {
- targetAngle += 360;
- }
- //3.4.3:
- let targetAngleN = targetAngle-180;
- //3.4.3.1:
- while (targetAngleN >= 360) {
- targetAngleN -= 360;
- }
- while (targetAngleN < 0) {
- targetAngleN += 360;
- }
- //3.4.4:
- if (targetAngle > 180) {
- //3.4.4.1:
- if (shotAngle < (targetAngle - SHOT_HOMING) && shotAngle > targetAngleN) {
- //3.4.4.1.1:
- ObjMove_SetAngle(obj,shotAngle+SHOT_HOMING);
- }
- //3.4.4.2:
- if (shotAngle > (targetAngle + SHOT_HOMING) || shotAngle < targetAngleN) {
- //3.4.4.2.1:
- ObjMove_SetAngle(obj,shotAngle-SHOT_HOMING);
- }
- //3.4.4.3:
- if (shotAngle >= (targetAngle - SHOT_HOMING) && shotAngle <= (targetAngle + SHOT_HOMING)) {
- //3.4.4.3.1:
- ObjMove_SetAngle(obj,targetAngle);
- }
- }
- //3.4.5:
- if (targetAngle < 180) {
- //3.4.5.1:
- if (shotAngle > targetAngleN || shotAngle < (targetAngle + SHOT_HOMING)) {
- //3.4.5.1.1:
- ObjMove_SetAngle(obj,shotAngle+SHOT_HOMING);
- }
- //3.4.5.2:
- if (shotAngle < targetAngleN && shotAngle > (targetAngle - SHOT_HOMING)) {
- //3.4.5.2.1:
- ObjMove_SetAngle(obj,shotAngle-SHOT_HOMING);
- }
- //3.4.5.3:
- if (shotAngle >= (targetAngle - SHOT_HOMING) && shotAngle <= (targetAngle + SHOT_HOMING)) {
- //3.4.5.3.1:
- ObjMove_SetAngle(obj,targetAngle);
- }
- }
- }
- }
- //4:
- yield;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement