NPC walk in front of player (Human Shield)

st3or

Villager
Member
Joined
Oct 4, 2019
Messages
5
Reaction score
0
First Language
English
Primarily Uses
RMMV
Hello guys, so I tried to do this already without success, and I think I'll need to use Script...

I want to make an NPC, of my choosing(on event triggerd), to follow me, and stay always in front of me(player). So to speak, to use it as a human shield.

I can make an NPC follow me, using Move Toward Player, Turn Toward Player, but I want to be always in front of player, where the player is facing.

Can you give me some insight, ideas?

Would I need to use Script..., if yes, how... I don't know much on scripts on this engine, I'm new.

Thanks a lot.
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
21,864
Reaction score
11,071
First Language
English
Primarily Uses
RMVXA
I won't move it to script requests straight away as there are probably other ways of doing it. If it turns out that it can only be done with a script, please Report this post and ask for it to be moved.
 

Heirukichi

Veteran
Veteran
Joined
Sep 24, 2015
Messages
1,387
Reaction score
581
First Language
Italian
Primarily Uses
RMVXA
but I want to be always in front of player,
What if the player turns toward another direction? How is your human shield supposed to react?
 

st3or

Villager
Member
Joined
Oct 4, 2019
Messages
5
Reaction score
0
First Language
English
Primarily Uses
RMMV
The human shield shoul move to be constantly, at any player movement, in front of him, in his face. So turning other direction shoul, activate the human shield to move fast in front of the player.
 

Heirukichi

Veteran
Veteran
Joined
Sep 24, 2015
Messages
1,387
Reaction score
581
First Language
Italian
Primarily Uses
RMVXA
If by "move fast" you mean transfer the human shield directly in front of the player, then it is possible. If by "move fast" you mean that the human shield is supposed to actually move there, it is not possible (not without accepting the fact that it will not stay there every time). When the player turns back (180°) the human shield should move 2 steps (1 to enter the player square and one to reach the final destination). That is already slow on its own when the player is standing still, if the player is moving it becomes even harder because the number of squares for that movement becomes 3.

All that could be theoretically done with a very fast movement, at some point the human shield would reach its destination, but if the player is dashing that becomes very ugly as the player would move too fast and the difference between the event speed and the player speed would be too small.

In the end everything comes down to the fact that in order to achieve this, the human shield is supposed to move even when the player is still, and there is no way it can reach its destination without taking some time (unless you directly transfer it there). In that time span, the player could move, turn around again, or do anything else, and that would mess up the timing. This is simple math:

The human shield movement when the player turns can be quantified in squares as:
Code:
2 + y
The player movement, on the other hand, can be quantified as
Code:
y
In this case x is the player position.

It goes without saying that
Code:
2 + y > y
regardless of the actual value of y.
 
Last edited:

st3or

Villager
Member
Joined
Oct 4, 2019
Messages
5
Reaction score
0
First Language
English
Primarily Uses
RMMV
Ok, so there still are 2 options.

1. To slow down the player, which would not be at random, (holding an human shield should slow anyone down logically)

2. Or to do the transfer thingy. Which is not bad either.

But I still don't know, a thing that is used in either of these options. How to tell the NPC, where the player is facing, that variable...

Can you help?
 

Heirukichi

Veteran
Veteran
Joined
Sep 24, 2015
Messages
1,387
Reaction score
581
First Language
Italian
Primarily Uses
RMVXA
2. Or to do the transfer thingy. Which is not bad either.
If the human shield is being directly held by the player then transferring it when the player turns is the way to go. If you wnat to add realism then you can even slow the player, that works too.

In order to transfer the event you simply need to store the player direction in a variable (you can do that with event commands) and then use a parallel process event that checks the player direction each frame. If the current direction is different than the one stored in the variable, you transfer the player at the coordinates obtaining by rounding the player X and Y value with the current direction.

Direction is as follows:
2 - Down
4 - Left
6 - Right
8 - Up

The rounded coordinates are (I am only going to list the ones that are different, the coordinate not listed stays the same as the player's), according to the player direction, the following:
2 - (Y + 1)
4 - (X - 1)
6 - (X + 1)
8 - (Y - 1)

Another option would be that of creating a bigger sprite for the player when he is holding a human shield. That would solve all your issues at once, although you have to remember that the sprite must be 9 times bigger than the normal one (3 times larger and 3 times taller).
 

st3or

Villager
Member
Joined
Oct 4, 2019
Messages
5
Reaction score
0
First Language
English
Primarily Uses
RMMV
Also, I didn't mention I think, I'm using RPG Maker MV, and didn't found a MV forum, so that's why I posted this here. Can it be done the same in MV or should I take the VX Ace?
 

Heirukichi

Veteran
Veteran
Joined
Sep 24, 2015
Messages
1,387
Reaction score
581
First Language
Italian
Primarily Uses
RMVXA
MV and ACE event commands are the same with the only exception being MV Plugin Command which does not exist in VX Ace, but anything you can do with that can easily be achieved with script calls so differences are literally minimal.
 

st3or

Villager
Member
Joined
Oct 4, 2019
Messages
5
Reaction score
0
First Language
English
Primarily Uses
RMMV
Ah, I know I may be asking too much, but, I'm really just starting to learn this, I know UE4 well, but I need to do a mission, in not much time, and UE4 is time consuming, so I took the advice of using RPG Maker, but it's a whole new world for me.

If you could take me step by step, I would be forever grateful.
 

Heirukichi

Veteran
Veteran
Joined
Sep 24, 2015
Messages
1,387
Reaction score
581
First Language
Italian
Primarily Uses
RMVXA
As storing such things in variables is very basic I strongly advice to follow Andar's tutorial link in my signature, it has a whole section that covers variables and switches usage. The tutorial is for VX Ace but, as I said, the event commands are the same and you can apply what is in there to MV as well (except for the scripting parts).

As for the transfer part you can use the "Set Event Location" command, you can find it in the second page of your event command list and you can designate the new position using variables (possible the ones where you stored the new position).
 

mlogan

Global Moderators
Global Mod
Joined
Mar 18, 2012
Messages
14,660
Reaction score
8,092
First Language
English
Primarily Uses
RMMV

I've moved this thread to MV Support. Please be sure to post your threads in the correct forum next time. Thank you.

 

Bex

Veteran
Veteran
Joined
Aug 2, 2013
Messages
1,350
Reaction score
333
First Language
German
Primarily Uses
RMMV
How about changing the Graphic of the Player to the Events Graphic and the Events Graphic to the Player Graphic?
Than it would look like the player is following the Event, while in reality its vice versa.
A Event that is looking like the player is following the Player which is looking like an Event.
 

Heirukichi

Veteran
Veteran
Joined
Sep 24, 2015
Messages
1,387
Reaction score
581
First Language
Italian
Primarily Uses
RMVXA
@Bex that would mess up the collisions though.
 

BK-tdm

Manga Maker
Veteran
Joined
Jun 21, 2018
Messages
151
Reaction score
136
First Language
English
Primarily Uses
RMMV
You need this for a literal "human shield"?

Because if thats your goal i did the same on a shooting game i have by merging sprites so the player is grabbing the enemy and walks with it on a hold, which ends up with one tile sprite, no conditionals, no events, no direction checking, no parallels, nothing!

Just a simple "switch character sprite to" event.

So check if what you want to do can be achieved visually instead of using a lot of parallel checks/branches/scripts.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

On the plus side, if all this rioting sparks another Covid outbreak... I will have a whole lot of time to work on my game. Not exactly how I wanted to get that time, but hey I'm a glass is half full... of RM kind of guy. :LZSwink:
A video once in a while won't hurt.
Have a craving for a Nesquik milkshake. No idea why. Haven't had one since I was a kid. lol. I remember them kinda tasting nice, but also leaving a lot of nasty powder at the bottom of the cup.
The more I think about it, the weirdest part of going to work post-virus will probably be getting used to seeing my coworkers' mouths again. :LZYshock:
I think one of my weirdest realizations is that my speed of game development would probably be about the same if I *didn't* work a full-time manual labor job.

Forum statistics

Threads
98,063
Messages
948,987
Members
129,340
Latest member
guangdi
Top