Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   The Exact Center (https://forums.graalonline.com/forums/showthread.php?t=76583)

Kyranki 08-31-2007 03:54 AM

The Exact Center
 
I've had a LOT of different people tell me different ways to get the exact center of the player. Now, of all that I've heard I know it's either one of two ways:

PHP Code:

temp.centerx player.1.5;
temp.centery player.2

Or....

PHP Code:

temp.centerx player.0.5;
temp.centery player.1.5


Which is it, this has confused me for so long...?

DustyPorViva 08-31-2007 04:22 AM

It depends on where you want the 'center' of the player. The x is always player.x+1.5, but the y, I usually prefer it in the center of the body, not the whole player.
The 'size' of the player is 3x3, this is shown in Graalshop by the 48x48 pixel box. Now, if you mean the center of that, then it's player.x+1.5 and playery+1.5, but I prefer player.x+1.5 and playery+2(or 2.5), which is near the center of the player's body.

coreys 08-31-2007 04:28 AM

Zeo knows the exact center of the player apparently...it's like a f'ing long decimal

Kyranki 08-31-2007 04:49 AM

Quote:

Originally Posted by DustyPorViva (Post 1344846)
It depends on where you want the 'center' of the player. The x is always player.x+1.5, but the y, I usually prefer it in the center of the body, not the whole player.
The 'size' of the player is 3x3, this is shown in Graalshop by the 48x48 pixel box. Now, if you mean the center of that, then it's player.x+1.5 and playery+1.5, but I prefer player.x+1.5 and playery+2(or 2.5), which is near the center of the player's body.

So if you wanted the exact center of a player.

Center X - player.x + 1.5
Center Y - player.y + 2

Because I want the center of the body.

Inverness 08-31-2007 04:51 AM

Quote:

Originally Posted by coreys (Post 1344849)
Zeo knows the exact center of the player apparently...it's like a f'ing long decimal

Uh, no its not. The player is 3x3 tiles (48x48 pixels). The center would be at 24x24 pixels and 1.5x1.5 tiles from the origin. There is no super-long number concerning it.

DustyPorViva 08-31-2007 04:58 AM

Quote:

Originally Posted by Kyranki (Post 1344856)
So if you wanted the exact center of a player.

Center X - player.x + 1.5
Center Y - player.y + 2

Because I want the center of the body.

Ya, but you can tag on a .25-.5 to the Y, depending on your preference.

theHAWKER 08-31-2007 05:17 AM

Quote:

Originally Posted by DustyPorViva (Post 1344860)
Ya, but you can tag on a .25-.5 to the Y, depending on your preference.

your words are just too exact for me... xD

Kyranki 08-31-2007 05:59 AM

While testing....

PHP Code:

  temp.cx player.1.5;
  
temp.cy player.1.75

Is moreso the center of the player, directly under the chin of the head so it's quite considered the center of the Graal body considering the size and proportions of the body.

coreys 08-31-2007 06:09 AM

Quote:

Originally Posted by Inverness (Post 1344858)
Uh, no its not. The player is 3x3 tiles (48x48 pixels). The center would be at 24x24 pixels and 1.5x1.5 tiles from the origin. There is no super-long number concerning it.

Not the center of the actual player, but the center of the actual body. Which I would think is the same thing, but apparently not. z.z

DustyPorViva 08-31-2007 06:12 AM

For stuff like baddies(where you want them to aim at the body), I'd say y+2 would be much more appropriate. But it really doesn't matter, but I personally think 1.75 is a little bit too above the body.

Kyranki 08-31-2007 07:37 AM

Quote:

Originally Posted by DustyPorViva (Post 1344869)
For stuff like baddies(where you want them to aim at the body), I'd say y+2 would be much more appropriate. But it really doesn't matter, but I personally think 1.75 is a little bit too above the body.

I checked 1.5 and was hoping it'd be 'center-ish' however it was too high, and I feel like 1.75 is perfect as I feel 2 is too low. Besides, I'm not even checking for baddy hits. I'm going something else along the lines of that with it/

Chompy 08-31-2007 12:04 PM

PHP Code:

temp.cx player.1.46875;
temp.cy player.1.96875

uhm?

Twinny 08-31-2007 12:36 PM

Quote:

Originally Posted by Chompy (Post 1344896)
PHP Code:

temp.cx player.1.46875;
temp.cy player.1.96875

uhm?

Dammit! You beat me to it! >_<. I remember'd that those are the figures Loriel came up with. Apparently "Uberpixelexact" >_<

Chompy 08-31-2007 12:40 PM

Quote:

Originally Posted by Twinny (Post 1344901)
Dammit! You beat me to it! >_<. I remember'd that those are the figures Loriel came up with. Apparently "Uberpixelexact" >_<

Yep :p

Admins 08-31-2007 01:09 PM

The blocking part of "showcharacters" and players is x=0.5, y=1, width=2, height=2, so the center would be x=1.5 and y=2

Chompy 08-31-2007 01:11 PM

Quote:

Originally Posted by Stefan (Post 1344906)
The blocking part of "showcharacters" and players is x=0.5, y=1, width=2, height=2, so the center would be x=1.5 and y=2

:O

Crow 08-31-2007 02:25 PM

If I want the exact center, and seriously, the exact one, I just do the following:

PHP Code:

temp.cx player.1.5 32;
temp.cy player.32

Well, thats the center of the part normally blocking, the 32*32 pixels at the bottom of the body Dusty pointed out. Why 1 / 32? Thats half a pixel ;P Very nice to remember I guess :]

Chompy 08-31-2007 02:34 PM

Quote:

Originally Posted by Crow (Post 1344919)
If I want the exact center, and seriously, the exact one, I just do the following:

PHP Code:

temp.cx player.1.5 32;
temp.cy player.32

Well, thats the center of the part normally blocking, the 32*32 pixels at the bottom of the body Dusty pointed out. Why 1 / 32? Thats half a pixel ;P Very nice to remember I guess :]

or
PHP Code:

temp.cx player.23.5/16;
temp.cy player.31.5/16

which is Loriels' method that he used in his Movement system ;o

But his movement system is compatible with gs1 so I've rewritten his movement system to work with gs2, and to use less cpu (gs1 didn't support temp. variables >_<) and I added running to it ;o

Inverness 08-31-2007 10:20 PM

Quote:

Originally Posted by Chompy (Post 1344896)
PHP Code:

temp.cx player.1.46875;
temp.cy player.1.96875

uhm?

Thats just going from tiles to pixels.

Chompy 08-31-2007 10:22 PM

Quote:

Originally Posted by Inverness (Post 1344974)
Thats just going from tiles to pixels.

PHP Code:

temp.cx player.23.5/16;
temp.cy player.31.5/16

then :p

Polo 08-31-2007 11:41 PM

You should not be subtracting 1/32 (half a pixel), as doing so will give you an innacurate result.

If you're wondering why, it's because a pixel has shape to it: it has both a left and right edge. The easiest way to demonstrate this is to draw 2 adjoining squares on a piece of paper with 0 and 2 written on the outside bottom corners, and 1 written on the touching corner. I'm fairly sure that you'll agree the centre is at 1 and not 0.5.

PHP Code:

  ___ ___
 
|   |   |
 |
___|___|
 
0   1   2 

In light of that, the usual coordinates to use for movement are a 2 by 2 square centred exactly on 1.5, 2 (just as Stefan said).

Kyranki 08-31-2007 11:50 PM

So what's the best calculation then Storm?

PHP Code:

temp.cx player.1;
temp.cy player.1

When using that the center is too 'high'. I seem to have started something here... o_o

Polo 09-01-2007 12:00 AM

Quote:

Originally Posted by Kyranki (Post 1344988)
So what's the best calculation then Storm?

For movement systems, I have always used...
NPC Code:
temp.cx = player.x + 1.5;
temp.cy = player.y + 2;


Which give the center of the players base (thats the area which blocks against walls). Add/subtract 1 from those positions to find the respective edges of this region. :)

Kyranki 09-01-2007 02:07 AM

Quote:

Originally Posted by Polo (Post 1344992)
For movement systems, I have always used...
NPC Code:
temp.cx = player.x + 1.5;
temp.cy = player.y + 2;


Which give the center of the players base (thats the area which blocks against walls). Add/subtract 1 from those positions to find the respective edges of this region. :)

I'm just getting the center of the player to calculate hit detection using the center of the attacker and each possible person to hit.

Googi 09-01-2007 02:52 AM

Quote:

Originally Posted by Kyranki (Post 1345007)
I'm just getting the center of the player to calculate hit detection using the center of the attacker and each possible person to hit.

So what are you looking for? The center of the player's "image"? player.x + 1 and player.y + 1.5 should do it for you.

Inverness 09-01-2007 03:05 AM

Quote:

Originally Posted by Googi (Post 1345008)
So what are you looking for? The center of the player's "image"? player.x + 1 and player.y + 1.5 should do it for you.

Not quite. Player images are 3x3 tiles.
Quote:

Originally Posted by Stefan
The blocking part of "showcharacters" and players is x=0.5, y=1, width=2, height=2, so the center would be x=1.5 and y=2

Do what Stefan said.

Googi 09-01-2007 07:05 AM

Quote:

Originally Posted by Inverness (Post 1345011)
Not quite. Player images are 3x3 tiles.

That might be the programmed size, but the image the player sees is not three tiles across.

xXziroXx 09-01-2007 12:13 PM

Quote:

Originally Posted by Googi (Post 1345034)
That might be the programmed size, but the image the player sees is not three tiles across.

Since he's trying to check if the player is it, and not anything with the image, he should do what Stefan said which gives you the progammed size (the only area where triggers are checked).

zokemon 09-01-2007 11:02 PM

Quote:

Originally Posted by Chompy (Post 1344896)
PHP Code:

temp.cx player.1.46875;
temp.cy player.1.96875

uhm?

This is true but often you are off-setting it the the pixel down right of your "center" so most just settle with 1.5,2. Unless you are doing like a movement system or something that is checking onwall checks or so, 1.5,2 will work much better for you.

Inverness 09-01-2007 11:23 PM

Quote:

Originally Posted by Googi (Post 1345034)
That might be the programmed size, but the image the player sees is not three tiles across.

The image the player sees is centered in the 3x3 box, meaning player.x+1.5 would be the vertical center of that box and the center of the player image. Stefan said center of player image would be player.x+1.5 and player.y+2

Googi 09-01-2007 11:55 PM

Quote:

Originally Posted by Inverness (Post 1345192)
The image the player sees is centered in the 3x3 box, meaning player.x+1.5 would be the vertical center of that box and the center of the player image. Stefan said center of player image would be player.x+1.5 and player.y+2

My mistake. I was using an inaccurate method for determining the center. It is indeed +1.5 and +2.

Inverness 09-02-2007 12:41 AM

Quote:

Originally Posted by Googi (Post 1345197)
My mistake. I was using an inaccurate method for determining the center. It is indeed +1.5 and +2.

Its only recently that I found out that the player box thing was 3x3 -.-, since I don't do ganis I never noticed that box in GraalShop.

Kristi 09-05-2007 04:15 PM

Zomg 3 pages of arguing this when Stefan answered it in the first? Why would you even begin to think Stefan was wrong?

zokemon 09-05-2007 05:33 PM

3 pages of arguing...?

Inverness 09-05-2007 11:48 PM

Quote:

Originally Posted by Kristi (Post 1345952)
Zomg 3 pages of arguing this when Stefan answered it in the first? Why would you even begin to think Stefan was wrong?

Thats what I said.

By the way, if just that takes up 3 pages then you should probably display more posts per page methinks? I do 30 a page myself.


All times are GMT +2. The time now is 06:17 PM.

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