Help - Search - Members - Calendar
Full Version: [Eventing] Event Collision Detection
RPG RPG Revolution Forums > Game Engines > RPG Maker VX Discussion > RPG Maker VX Tutorials
BasharTeg6
Ever want to see two old guys duking it out in your RPG? Do you want a reaction to occur between an event that looks like fire and another event that looks like water? You might need event collision detection. Here is a tutorial explaining how conditional branches and variables can be used to find out if two events are within, at, or beyond a certain range on the X and Y plane.

You need to set up 4 variables to determine the locations of the events. Then you need to set up a persistent event (parallel process) to periodically store the events' locations into these variables. Here's an example:

Store Variables Event (parallel process, can be triggered by whatever switch you want)

Set 'Event_1_X' = Event 1's Map X
Set 'Event_1_Y' = Event 1's Map Y
Set 'Event_2_X' = Event 2's Map X
Set 'Event_2_Y' = Event 2's Map Y
Wait <x> frames.

The wait is there to prevent excessive lag by the event constantly firing. Although, since it's only storing variables, it might not be so bad anyway. But I left it there just in case.

Now that you have variables for the events' locations you can use conditional branches to compare them. You'll have to do a little arithmetic here, and set up some new variables.

Conditional Branch:
If 'Event_1_X' is greater than 'Event_2_X'
---Set 'Event_1_X' -= 'Event_2_X'
---Set 'X_Distance' = 'Event_1_X'
ELSE
---Set 'Event_2_X' -= 'Event_1_X'
---Set 'X_Distance' = 'Event_2_X'

Now X_Distance should be a positive number depicting the difference between Event 1's map X and Event 2's map X. In summary, this will show how far apart the events are horizontally. Next you do the same thing for the Y's to determine vertical distance.

So now you should have positive numbers (or zero) for both X_Distance and Y_Distance. The next thing you need to do then is run two conditional branches for each to find out if the events are less than, equal to, or greater than a specified distance.

Conditional Branch:
If X_Distance < 2
---Conditional Branch: If Y_Distance < 2
------(Then put whatever you want to happen if events are next to each other)

You can apply this same technique to find out if two events are within, beyond, or at a certain range.

Screenshots:



Here is a demo so you can see this in action.

Good luck!

-Bash
Robz
Thank you for this! biggrin.gif at first it looked REALLY confusing, but after a while you start to catch on and it's a cakewalk ^^
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2013 Invision Power Services, Inc.