MV (Event check for player direction towards it?) "So you wanna make a soccer minigame"

I seem to have finally run into somewhat of a hefty portion of event interaction...

I want to make a Soccer minigame, and thus I need to program a ball, and as such I want the ball to be able to be kicked by the player (and NPC's but... Yeah.) so I need it to somehow be able to check whether the player is faced towards the ball... Is this possible?

I initially assumed this would be something programmed into the base engine but yet after finding out it wasn't even googling for a bit lead me halfway to nowhere... Is there any "simple" trick or line of code one could use to create a conditional branch where an event checks whether or not the player is facing towards the event specifically or not when activated so that the ball so to say can not be kicked backwards for example?

1761397761937.png
Well it ... is part of the base engine in the conditional branches:
1761398720801.png
the answer above works directly for "player touch" events.

but if you have a moving event and use "event touch", then you need to use a coordinate comparison (X/Y, available through control variable : game data) in addition to the facing to prevent a trigger from above while the player is facing down and similar.
You could check every direction and do several conditional statements to run your code based on that (in which you also have to compare coordinates, etc).

MV does not have a method that checks for when a character is turned toward another character.

There is a method to make the character TURN toward another character which, with a few conditions and a return statement, you can create a method like this one to use which would do the above for you to use as a script call:
Spoiler
JavaScript:
void (($gc) => { // Game Character
    $gc.isTurnedTowardCharacter = function(character) {
        const sx = this.deltaXFrom(character.x);
        const sy = this.deltaYFrom(character.y);
        const d  = this.direction();
        if (Math.abs(sx) > Math.abs(sy)) {
            if (sx > 0) {
                if (d === 4) return true;
            } else {
                if (d === 6) return true;
            }
        } else if (sy !== 0) {
            if (sy > 0) {
                if (d === 8) return true;
            } else {
                if (d === 2) return true;
            }
        }
        return false;
    }
})(Game_Character.prototype);

Then in your conditional branch, you can use the script call portion and check the player with the event (this.character(0) refers to the event running the code):
Spoiler
JavaScript:
◇If : Script : this.character(0).isTurnedTowardCharacter($gamePlayer)
  ◇Comment: Your code goes here
  ◇
: End
◇
You should be able to reference any character to compare with any other character:
Spoiler
JavaScript:
$gamePlayer.isTurnedTowardCharacter($gameMap.event(17));
$gameMap.event(2).isTurnedTowardCharacter($gameMap.event(9));
Eventing you can conditional branch a way to check what direction the player is in, or even what block they are standing on, but I don't think there is a way to do this without scripting something that checks what block the ball is on vs what block the player is on and the direction as well. Then it would check if the player is even standing next to the ball as well and use a button to move the ball or play an animation of kicking.
You will need to create a parallel process event that constantly checks the coordinates of NPC and the ball.
But how do we make the NPC run to the ball? We'll use the same logic as we used for creating the Caterpillar using events:
1761413942900.png


So, to conclude, to make the NPC kick the ball, simply check if the coordinates are exactly the same:
1761414069033.png


Since I assume the ball graphic will be small and should appear to be at the player's feet, it's best to make the collision only happen when they are actually occupying the same tile:
1761414285573.png




This is the simplest of the simple, meaning that it will be necessary to create more conditions regarding coordinates and directions so that the NPC can go to the center of the goal instead of just going to the right.

Original thread: https://forums.rpgmakerweb.com/threads/event-check-for-player-direction-towards-it-so-you-wanna-make-a-soccer-minigame.180704/