Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Box Checks (https://forums.graalonline.com/forums/showthread.php?t=134258725)

Switch 04-11-2010 10:23 AM

Box Checks
 
1 Attachment(s)
Is there any way to check if a number that is between a set of two numbers is inside of a point between two numbers? Mostly for checking if any point of a player's body is inside of an area, similar to findareanpcs().
I think my picture will explain it better than i could in words.
Note that there's no definite location of where the number(s) could be (as it could be hit in various spaces), so I can't check for only one point/general location.

cbk1994 04-11-2010 10:38 AM

1 Attachment(s)
Just use a point to tell if it's inside. Alternatively, use radiuses.

Switch 04-11-2010 10:51 PM

Quote:

Originally Posted by Switch (Post 1568455)
Note that there's no definite location of where the number(s) could be (as it could be hit in various spaces), so I can't check for only one point/general location.

Quote:

Originally Posted by cbk1994 (Post 1568458)
Just use a point to tell if it's inside. Alternatively, use radiuses.

And I can't use radii because that can cut off corners.

fowlplay4 04-11-2010 10:58 PM

You want to do this..?

PHP Code:

if (player.x in |this.6this.6| && player.y in |this.6this.6|) {
  
// In Box


Use that and you could..

1. Check the center
2. Check the corners

Switch 04-11-2010 11:09 PM

Quote:

Originally Posted by fowlplay4 (Post 1568558)
You want to do this..?

PHP Code:

if (player.x in |this.6this.6| && player.y in |this.6this.6|) {
  
// In Box


Use that and you could..

1. Check the center
2. Check the corners

Can't really because it's a largish area.

More along the lines of this (though not possible)
PHP Code:

if (|player.xplayer.x+3in |this.xthis.x+this.movementx| && |player.yplayer.y+3in |this.ythis.y+this.movementy|) {
  
//overlapping points



fowlplay4 04-11-2010 11:18 PM

Then use a for loop?

PHP Code:

for (temp.player.xtemp.< (player.3); temp.i++) {
  for (
temp.player.ytemp.< (player.3); temp.j++) {
    if (
temp.i in |this.6this.6| && temp.j in |this.6this.6|) { 
      
// In Box 
    

  }



Switch 04-11-2010 11:26 PM

Quote:

Originally Posted by fowlplay4 (Post 1568565)
Then use a for loop?

PHP Code:

for (temp.player.xtemp.< (player.3); temp.i++) {
  for (
temp.player.ytemp.< (player.3); temp.j++) {
    if (
temp.i in |this.6this.6| && temp.j in |this.6this.6|) { 
      
// In Box 
    

  }



I was seeing if there was a way to do it without loops.

WhiteDragon 04-11-2010 11:35 PM

Check out the separating axis theorem.

Switch 04-12-2010 10:44 PM

Quote:

Originally Posted by WhiteDragon (Post 1568572)
Check out the separating axis theorem.

Although not as simple as this, it gave me a good idea on how to go about this, and works perfect! Thanks for the springboard. :)
Checked if either of the image's edges are inside another one, so there are 4 checks each for horizontal and vertical.

Switch 05-16-2010 11:13 PM

Forgot to post this, but if anyone is wondering what I've done for this, I've posted it below.

PHP Code:

function checkCollision(firstxfirstyfirstwfirsthsecondxsecondysecondwsecondh) {
  if ((
firstx <= secondx && firstx+firstw >= secondx+secondw) || (firstx >= secondx && firstx+firstw <= secondx+secondw) || (firstx <= secondx && firstx+firstw >= secondx) || (firstx <= secondx+secondw && firstx+firstw >= secondx+secondw)) {
    if ((
firsty <= secondy && firsty+firsth >= secondy+secondh) || (firsty >= secondy && firsty+firsth <= secondy+secondh) || (firsty <= secondy && firsty+firsth >= secondy) || (firsty <= secondy+secondh && firsty+firsth >= secondy+secondh)) {
      return 
true;
    }
  }




All times are GMT +2. The time now is 01:01 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.