Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Oz on Sat 31/07/2004 12:25:20

Title: Centering the character baseline
Post by: Oz on Sat 31/07/2004 12:25:20
I would like to permanently move the character baseline from 0 (the character's feet) to center (the character's waist). I've been toying around with SetCharacterBaseline without success. What would the correct SetCharacterBaseline command be? The char is 16 pixels tall. The reason I want to move the baseline is that I'm working on a top-down adventure game. I want the collision detection for the walkable areas to be calculated from the character's center point instead of its feet.

Thanks!
Title: Re: Centering the character baseline
Post by: Fabiano on Sat 31/07/2004 15:53:56
hm.. i guess if u use setcharacterbaseline (char, character[char].y-16); in the repeated execute would work
Title: Re: Centering the character baseline
Post by: Oz on Sat 31/07/2004 16:20:44
Hmmm. No luck there. It doesn't seem to move the baseline at all. I wish there was a debug feature that would let you view baselines at runtime.
Title: Re: Centering the character baseline
Post by: Goot on Sat 31/07/2004 18:39:26
I don't think walkable areas test for the baseline. Just the x,y coordinate. I had the same problem when I tried to do a top view. I made an invisible player character and another character (the one with the actual character's picture) was constantly put below it so the invisible character was in the middle of the other one.

In repeatedly execute:

character[CHAR].x=character[INVISIBLEGUY].x;
character[CHAR].y=character[INVISIBLEGUY].y+half the character's hight

The invisible guy's x and y coordinates (middle of the other guy) will trigger hotstops and stuff.
Title: Re: Centering the character baseline
Post by: on Sat 31/07/2004 18:54:50
SetCharacterBaseline (EGO, character[EGO].y-8);

in the repeatedly execute should work, but since you say it doesn't, you could try SetCharacterViewOffset instead, e.g.:

SetCharacterViewOffset (EGO, 1, 0, character[EGO].y-8);

This should only need to be run once (at game start), unless you want to change the character view (like if they change clothes). However, you'll need to have a similar line for every character in the game, e.g.:

function game_start() {
  SetCharacterViewOffset (EGO, 1, 0, character[EGO].y-8);
  SetCharacterViewOffset (NPC, 3, 0, character[NPC].y-8);
  SetCharacterViewOffset (ENEMY, 4, 0, character[ENEMY].y-8);
  SetCharacterViewOffset (BOB, 2, 0, character[BOB].y-8);
  etc...
}

Hope this helps.
Title: Re: Centering the character baseline
Post by: Oz on Sun 01/08/2004 11:38:09
Quote from: Goot on Sat 31/07/2004 18:39:26
I don't think walkable areas test for the baseline.

Does anyone know if this is the case? It seems that the player will move his feet to the top and bottom of the walkable area before stopping, indicating that the baseline (0) is used for detection.

Ashen_Away,

Thanks, I'll try toying around with SetCharacterViewOffset.
Title: Re: Centering the character baseline
Post by: Snarky on Mon 02/08/2004 00:04:38
There have already been (http://www.agsforums.com/yabb/index.php?topic=10790.0) several (http://www.agsforums.com/yabb/index.php?topic=15574.0) other (http://www.agsforums.com/yabb/index.php?topic=15364.0) threads (http://www.agsforums.com/yabb/index.php?topic=14736.0) about this recently. Basically, it cannot currently been done: The characters' "hotspot" (the point used as their position for purposes of walkable areas and walk-to commands) is fixed to the bottom center. However, it's on CJ's to-do list (and may be in the latest beta?), and there are workarounds.

If you just need to change the walk-to point, you can use something like:

if (GetCursorMode()==MODE_WALK){
Ã,  Ã,  Ã,  Ã,  MoveCharacter(GUYBRUSH, mouse.x, mouse.y+29);
}


The best workaround for the walkable areas is probably to manually offset them by the appropriate number of pixels. This is very easy to do if you're defining your walkable areas in a painting application.
Title: Re: Centering the character baseline
Post by: Oz on Mon 02/08/2004 15:27:20
Snarky,

Thanks for sorting that out. The problem is that producing a top-down game requires you to be able to center the character hotspot for proper alignment of the character in walkable areas. I'll try your workaround and see what I come up with!
Title: Re: Centering the character baseline
Post by: Proskrito on Mon 02/08/2004 16:34:32
in the newest versions of ags, there is a character[CHARID].z variable, you could try to modify it to set the middle point for walkabe areas higher.

EDIT: i have made a function for you, try it and see if thats what you wanted:

function CenterCharacterBaseline(int charid){
int charsprite = GetGameParameter(GP_FRAMEIMAGE,character[charid].view+1, character[charid].loop, character[charid].frame);
int spriteheight= GetGameParameter(GP_SPRITEHEIGHT, charsprite ,0,0);
character[charid].z=-(spriteheight/2);
}