Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: on Sun 14/09/2003 16:24:55

Title: Character walking on object
Post by: on Sun 14/09/2003 16:24:55
That happens. How I make it not to?

I guess I could fix the walkable area somehow, but is that the only way?
Title: Re:Character walking on object
Post by: Scorpiorus on Sun 14/09/2003 17:38:51
Also you can try AreCharObjColliding() script function by placing it within room's repeatedly.

Try the next code and see if it works:

//room script:

int pX, pY;
function room_*() {
// script for room: Repeatedly execute

int GPC = GetPlayerCharacter();

if (AreCharObjColliding (GPC, <object_number>) == 1) {
// if there is a collision

StopMoving(GPC); //stop player
// move him back a bit
character[GPC].x = pX;
character[GPC].y = pY;

}

pX = character[GPC].x;
pY = character[GPC].y;


}
Title: Re:Character walking on object
Post by: on Sun 14/09/2003 18:45:03
It didn't work, or then I just didn't understand it clearly enough.

So could you tell me little closer, what I should do with that script?
Title: Re:Character walking on object
Post by: Scummbuddy on Sun 14/09/2003 19:27:08
No, just check out baselines, and yes, you will have to mess with your walkable area.

http://www.adventuregamestudio.co.uk/acintro2.htm
Title: Re:Character walking on object
Post by: Scorpiorus on Sun 14/09/2003 20:30:47
Edit by strazer:

AGS v2.7 Beta 7 added the Solid, BlockingWidth and BlockingHeight properties to Objects.



Ok, so there are two ways:

1. Using walkable area
Just erase walkable area under the object.

2. Using AreCharObjColliding() AGS script function

Open room file. Next, click Interactions - choose Repeatedly execute - add action Run script. Now close the Interaction editor and click on the edit whole room script button {}. You'll see something like:

// room script file

function room_*() {
  // script for room: Repeatedly execute
}

note: you'll see a letter instead of '*' (ex: room_a() etc.)

Now add the script code:

// room script file

int pX, pY; // <- place them here (outside of the function!!!)
function room_*() {
  // script for room: Repeatedly execute

// first we get current player character 
  int GPC = GetPlayerCharacter();

// then check if there is a collision between the char and the object
// you have to replace the <object number> with the
// appropriate object number!

  if (AreCharObjColliding (GPC, <object number>) == 1) {
// if there is a collision

    StopMoving(GPC); //stop player and ...
    // ... move him back a bit
    character[GPC].x = pX;
    character[GPC].y = pY;

  }

// here we are saving current character position
// to get back to it later (if required)

  pX = character[GPC].x;
  pY = character[GPC].y;
 
}


How it goes?

If you have some troubles don't hesitate to ask, but, please tell what exactly is going wrong. ;)




Title: Re:Character walking on object
Post by: InCreator on Wed 15/10/2003 17:38:30
Collision detection? In every step? Sounds very sloooow for me.
Title: Re:Character walking on object
Post by: Scorpiorus on Thu 16/10/2003 18:55:08
Since there are no 'while' loops or something like that, it would work quite fast. Besides, it's almost the only reasonable way to use the collision detection function.

~Cheers