Page 1 of 1

How to "detect" the edge of a cliff?

PostPosted: Wed Feb 02, 2011 4:45 pm
by Toasterman
I have an enemy that moves back and forth- when it hits a wall it changes direction
The other end of it's route may be empty space, How can I detect the lack of floor (where the ground stops) and do something based on that?

I think you can use CollisionFree, but I haven't been able to get that to work

any ideas?

Re: How to "detect" the edge of a cliff?

PostPosted: Wed Feb 02, 2011 9:09 pm
by saikspaik
It's very easy.

Create Actor Event
Code: Select all
xvelocity = 4; //Four - it's your speed


Draw Actor Event
Code: Select all
if (CollisionFree("Event Actor", x, y+4)) {
    xvelocity *= -1; //Move in opposite direction
}


A simple example is attached.

Re: How to "detect" the edge of a cliff?

PostPosted: Wed Feb 02, 2011 9:36 pm
by Game A Gogo
saikspaik wrote:It's very easy.

Create Actor Event
Code: Select all
xvelocity = 4; //Four - it's your speed


Draw Actor Event
Code: Select all
if (CollisionFree("Event Actor", x, y+4)) {
    xvelocity *= -1; //Move in opposite direction
}


A simple example is attached.

CollisionFree("Event Actor", x, y+yvelocity) could work better in this case

Re: How to "detect" the edge of a cliff?

PostPosted: Thu Feb 03, 2011 7:08 am
by saikspaik
Game A Gogo wrote:CollisionFree("Event Actor", x, y+yvelocity) could work better in this case

I agree, but only if yvelocity greater than zero.

Re: How to "detect" the edge of a cliff?

PostPosted: Thu Feb 03, 2011 9:54 pm
by Toasterman
Can you be specific as to what it is colliding with?

That is how I had set it up in early attempts, but I have a canvas stretched across that whole area (to make a sky) that I think is interfering with the process.

Is there a way to check if it is colliding with the ground, and not everything? (using CollisionFree)

Re: How to "detect" the edge of a cliff?

PostPosted: Fri Feb 04, 2011 12:25 am
by saikspaik
Toasterman wrote:Is there a way to check if it is colliding with the ground, and not everything? (using CollisionFree)

Fortunately, such a way exists.
You can use CollisionState function to disable collisions for all actors exept the ground, or just for your sky canvas :)

Add this line of code to your "sky canvas", in Create Actor event
Code: Select all
CollisionState("Event Actor", DISABLE);

Re: How to "detect" the edge of a cliff?

PostPosted: Fri Feb 04, 2011 10:57 am
by Game A Gogo
Code: Select all
int n,i;
Actor*actors=NULL;
actors=getAllActorsInCollision("Event Actor",&n);
if(actors)
{
    for(i = 0; i < n; i++)
    {
        if(strcmp(actors[i].name,"GROUND_ACTOR")==0)//Action to happen when colliding with GROUND_ACTOR
    }
}

This is what I used for creating my collision system in the latest Jason's World

Re: How to "detect" the edge of a cliff?

PostPosted: Sat Feb 05, 2011 12:47 am
by Toasterman
Thanks! It's all cleared up :D

Re: How to "detect" the edge of a cliff?

PostPosted: Wed Feb 16, 2011 3:30 am
by Toasterman
Heeeey.... I've got another problem...
what if something else is under the "checked" area? Setting collision state to "no" works fine if it is something static like background, but what if it is your main character or another enemy or something (something that would need to collide with the enemy).

My enemy works great unless you stand right beneath it, at which point it will float in space, thinking the character is ground...
I've been thinking about this for a while and can't think of a solution! Can anybody help?

Re: How to "detect" the edge of a cliff?

PostPosted: Wed Feb 16, 2011 10:28 am
by Game A Gogo
There are no good solution to this. the best one I've found was to work with GetAllActorsInCollision, and check in a for loop if an actor in collision happens to be named to an actor it must collide.
Then you can specify what it does with each actor. this might a be a bit hard S: