RedEdge967 / Spider-Man

A mini figure game of Spiderman with more villains to fight 🕷️🕸️ ~Give a Star~ ~Contributions are welcomed~

Home Page:https://rededge967.github.io/Spider-Man

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NPC not turning around in the direction of the player

Scrappers-glitch opened this issue · comments

Hello, nice game !
I just noticed the non-player characters aren't turning around if you pass them and aren't jumping with you, to make the game more cooler, you may consider these parts :

  1. Easy difficulty -> the game as it is now.
  2. Medium -> add the NPC turn around firing you from your back while escaping him.
  3. Hard -> add the NPC jump with you.
  4. Realistic -> add NPC can fire multiple things or take 2 of your life points if you hit his bullet.

Some hints :

  • How to know your location with respect to the NPC ?
    => Assuming you are at point 0 and the NPC at point 10 game units, then :
/**
* Positions the NPC to face the player and
* controls the NPC melee attack.
*/
void attackLoop(tpf) {
    const var distance = npc.getNPCLocation() - player.getPlayerLocation();
    if (distance < 0) {
         npc.faceToScreenLeft();
    } else if (distance > 0) {
         npc.faceToScreenRight();
    } else {
         npc.activateMeleeAttack();
    }
}

void update(tpf) {
    attackLoop(tpf);
}

What this basically does, is it gets the linear distance (not 3d distance), if the distance is zero then npc activates melee attack, distance is less than zero then that means the player is before the npc so position npc facing the left of the screen, and vice versa in case of the distance bigger than zero, you can optimize this more using the math stdlib of js.

Note : i didn't look at the sources, if you are using Vector2 or threejs then you better use the distance formula = sqrt (pow(x2 - x1, 2) + pow(y2 - y1, 2));.

Hi! That's a good idea. But I don't have a idea to look up for this project any further. But you can always open any PR for this repo. Since then I will keep this issue open. Be sure to open a PR with your changes when you can.

Happy coding

Unfortunately, I don't have enough time for now, and I am not a web developer, just leaning js for some very specific targets on android, but sure if I have found enough time, I will do a PR.

Sure @Scrappers-glitch anytime when you can

I will close this issue for now. when you have free time to open a PR, reopen this issue.