HOW TO MAKE ENEMIES WALK TOWARDS YOU WHEN YOU GET CLOSE?

Posts

Pages: 1
Hey people.

How do I make a dist function in rpgmaker 2k3? I know its something to do with a switch. I want the enemies to move towards the player when they "see" the player.



Psuodocode.

Page 1
Move randomly

Page 2
If dist (playerx, playery, this.x, this.y) less than 3
move towards player


Thanks
Flik

pianotm
The TM is for Totally Magical.
32347
This isn't totally straight forward. There's a few ways to do it, but probably the best way is the trigonometry script. (scripting in the events. This is not a five minute project. Be prepared to devote some time to setting this up.)

https://rpgmaker.net/tutorials/479/

This even gives a Metal Gear Solid style stealth example where an enemy gives chase if it "sees" the PC.

This is much easier to do in XP, VX Ace, MV and such where plugins exist.
Here's a script implements a "vision" system where the player character will trigger an event if they're within a certain range of the event... n' stuff. It has a camo system too, but it's pretty broken (as in sneaking basically mitigates any chance of the event being triggered) and it replaces running with sneaking (there are ways to circumvent this). But besides all of that baloney, it's pretty darn solid.

https://rpgmaker.net/scripts/606/
It was made by Velvet Isis.
pianotm
The TM is for Totally Magical.
32347
Cringinsid
https://rpgmaker.net/scripts/606/
It was made by Velvet Isis.


That's a VX Ace script. Even though OP fails to tag in the title, they state in the body that the engine is 2K3.
The trig stuff would work, but if you just want enemies to walk towards you when you're nearby, I'd check out Kentona's wonderful Proximity Detection for Events tutorial.

It's what I used to get the enemies to walk towards the player in Dirge, so I know it'll work for sure.
Surround the 'chasing event' with events that block off it's 'idle roaming' area. Have the panels that block off the event and the currently roaming event be below the player. Have the events that block off the roaming event on touch activate a switch that fires up a second page on the roaming event to now follow the player, and make all the floor tiles that were previously 'blocking' the roaming event have thru turned on. (make sure the chaser is now on same level, and do whatever it does other than that). Now, this will make it to where the event COULD be two tiles or however many tiles away, but you can also place the triggering event tiles a bit further out from it's 'blocked off' area to avoid this.

Hope it makes sense.
author=Sidewinder
The trig stuff would work, but if you just want enemies to walk towards you when you're nearby, I'd check out Kentona's wonderful Proximity Detection for Events tutorial.

It's what I used to get the enemies to walk towards the player in Dirge, so I know it'll work for sure.
author=Sidewinder
The trig stuff would work, but if you just want enemies to walk towards you when you're nearby, I'd check out Kentona's wonderful Proximity Detection for Events tutorial.

It's what I used to get the enemies to walk towards the player in Dirge, so I know it'll work for sure.



Does that work fot multiple enemies?
pianotm
The TM is for Totally Magical.
32347
That depends. How many enemies do you want to be able to follow the player? You'll have to make separate events for each of them, which is fine because you can copy-paste, but you'll need to make new variables and switches for each one. Fortunately, this detection formula doesn't look terribly complex.
author=flik9999
Does that work fot multiple enemies?

With a little creativity, yeah.
Sooz
They told me I was mad when I said I was going to create a spidertable. Who’s laughing now!!!
5354
Normally I would suggest getting their attention and saying, "Hey buddy, I got an extra ice cream cone, wanna take it off my hands?" but right now I think the social distancing thing would discourage most people.
I'd guess you can use a common event, if you're careful with variables.
You'd have to use a pointer variable set to the id of the switch to toggle when calling the common event.

Here's some cheats for measuring distances to avoid trigonometry.
I've written all these in pseudo code, but they can be implemented with 2k3 control variables & conditional branch commands.
1) skip the square root
dx = x1 - x2
dx = dx * dx
dy = y1 - y2
dy = dy * dy
d = dx + dy
normally you'd take a square root here, to get the distance.
But if you just want to test if the distance is less than a certain range, compare it with the square of the constant distance
if( d >= 9 ) # true if the distance is >= 3 tiles.

2) just add x and y distances
dx = x1 - x2
if( dx < 0 ) dx = -dx # or use the 'abs' function if available
dy = y1 - y2
if( dy < 0 ) dy = -dy
d = dx + dy

This gives a diamond shape hit detection, like movement in fire emblem type tactics games. The distance is the number of tile moves between the two positions for 4 directional movement.
So the loss of accuracy may be an advantage

3) use the greater of x and y distances
dx = x1 - x2
if( dx < 0 ) dx = -dx # or use the 'abs' function if available
dy = y1 - y2
if( dy < 0 ) dy = -dy
d = max(dx, dy)

This one gives a square detection area, again cheap and cheerful for tile based games where you don't need to be terribly accurate.
Pages: 1