Jump to content

Simplest trigger


VeTaL
 Share

Recommended Posts

I want to make the simplest trigger, which would be triggered as player moved far from center of the map.

Which one would be the simplest?

 

1) calculate by Pythagoras theorem:

 if (sqrt( sqr (player.x - center.x) + sqr ( player.y - center.y)) > radius) then ... 

it is perfect for my needs, but i'm looking for more simple solution as this consist of two sqr's and one sqrt.

 

2) calculate by squares:

 if ((((player.x - center.x) * ( player.y - center.y)) / 2) > radius) then ...

this is lot faster, but not too precious : (player.x - center.x) can be too large, but if ( player.y - center.y) would be too small, object would be still counted as "inside" the radius even if he would be far away.

 

3) add a physical sphere and trigger event when player wouldn't be inside a sphere

 

 

any ideas about this?

Working on LeaFAQ :)

Link to comment
Share on other sites

I guess EntityDistance does the Pythagorean algorithm anyway. And still, this allows for a low Y value and high X value or vice-versa.

The best method for your situation would really be the physical sphere, or a center inequation from the conics formulas.

Link to comment
Share on other sites

I think i can use fact, that center of the trigger is map center. So, in another words, i can just check

[if ((player.x < radius) && (player.x > -radius) && (player.y < radius) && player.y > -radius))]

 

Looking like it would be the fastest solution, but it would be square, not sircle.

Working on LeaFAQ :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...