Character walking on object

Started by lammhult, Sun 14/09/2003 16:24:55

Previous topic - Next topic

lammhult

That happens. How I make it not to?

I guess I could fix the walkable area somehow, but is that the only way?

Scorpiorus

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;


}

lammhult

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?

Scummbuddy

#3
No, just check out baselines, and yes, you will have to mess with your walkable area.

http://www.adventuregamestudio.co.uk/acintro2.htm
- Oh great, I'm stuck in colonial times, tentacles are taking over the world, and now the toilets backing up.
- No, I mean it's really STUCK. Like adventure-game stuck.
-Hoagie from DOTT

Scorpiorus

#4
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. ;)





InCreator

Collision detection? In every step? Sounds very sloooow for me.

Scorpiorus

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

SMF spam blocked by CleanTalk