How to "detect" the edge of a cliff?

Game Editor comments and discussion.

How to "detect" the edge of a cliff?

Postby Toasterman » Wed Feb 02, 2011 4:45 pm

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?
"If there are no stupid questions, what kind of questions do stupid people ask? Do they get smart just in time to ask a question? -Scott Adams

Hey! I've got okayish internet now! Now I can try all those cool demos I've seen!
User avatar
Toasterman
 
Posts: 75
Joined: Thu Jul 22, 2010 4:22 am
Location: Drowning in Dial-Up Ocean
Score: 7 Give a positive score

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

Postby saikspaik » Wed Feb 02, 2011 9:09 pm

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.
Attachments
EdgeDetect.zip
Simple example
(9.01 KiB) Downloaded 97 times
saikspaik
 
Posts: 14
Joined: Wed Jan 05, 2011 8:17 am
Score: 1 Give a positive score

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

Postby Game A Gogo » Wed Feb 02, 2011 9:36 pm

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
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

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

Postby saikspaik » Thu Feb 03, 2011 7:08 am

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.
saikspaik
 
Posts: 14
Joined: Wed Jan 05, 2011 8:17 am
Score: 1 Give a positive score

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

Postby Toasterman » Thu Feb 03, 2011 9:54 pm

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)
"If there are no stupid questions, what kind of questions do stupid people ask? Do they get smart just in time to ask a question? -Scott Adams

Hey! I've got okayish internet now! Now I can try all those cool demos I've seen!
User avatar
Toasterman
 
Posts: 75
Joined: Thu Jul 22, 2010 4:22 am
Location: Drowning in Dial-Up Ocean
Score: 7 Give a positive score

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

Postby saikspaik » Fri Feb 04, 2011 12:25 am

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);
saikspaik
 
Posts: 14
Joined: Wed Jan 05, 2011 8:17 am
Score: 1 Give a positive score

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

Postby Game A Gogo » Fri Feb 04, 2011 10:57 am

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
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

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

Postby Toasterman » Sat Feb 05, 2011 12:47 am

Thanks! It's all cleared up :D
"If there are no stupid questions, what kind of questions do stupid people ask? Do they get smart just in time to ask a question? -Scott Adams

Hey! I've got okayish internet now! Now I can try all those cool demos I've seen!
User avatar
Toasterman
 
Posts: 75
Joined: Thu Jul 22, 2010 4:22 am
Location: Drowning in Dial-Up Ocean
Score: 7 Give a positive score

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

Postby Toasterman » Wed Feb 16, 2011 3:30 am

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?
"If there are no stupid questions, what kind of questions do stupid people ask? Do they get smart just in time to ask a question? -Scott Adams

Hey! I've got okayish internet now! Now I can try all those cool demos I've seen!
User avatar
Toasterman
 
Posts: 75
Joined: Thu Jul 22, 2010 4:22 am
Location: Drowning in Dial-Up Ocean
Score: 7 Give a positive score

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

Postby Game A Gogo » Wed Feb 16, 2011 10:28 am

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:
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest

cron