Page 1 of 2

Alternative to CollisionFree - Collision Free From Actor!

PostPosted: Fri Mar 04, 2011 7:35 pm
by lcl
Hello!

In development work of my new game I found out that I need a function like CollisionFree(); but different version,
Collision Free From Actor! I started working with it, and got it done! And the best thing is that it works just perfect!

Here is the code for function:
Code: Select all
int collFree(int posX, int posY, char Name[50]) //colliding positions and the actor that we want to know if we are collision free from
{
    int temp;' //return value
    Actor * coll;
    coll = getactor(posX, posY); //actor that is collided

    temp = (strcmp(coll->name, Name) != 0); //compare the actors names

    return temp; //return temp = collision free or not
}

As you see, the code is really easy one.

This will make the controlling of enemy actors a lot easier, won't it? :)
And here's a demo for you!

Re: Alternative to CollisionFree - Collision Free From Actor

PostPosted: Fri Mar 04, 2011 7:58 pm
by AnarchCassius
Heh, great minds think alike. I just implemented A* in my game and wound up using this over CollisionFree. There are unfortunately issues with both that I can see.

CollisionFree is slow and only detects collision or not... if the area has a collidable object, even one that doesn't generate a physical response like a pick-up item, you would get a positive. Even worse, the player target is usually collidable so if any part extends out of the target cell it can create false blocking in pathfinding.

This other method is very nice for adjusting by object type but it has a major limitation, it's only scanning the top-most pixel at those exact coords. You won't know what's underneath or directly adjacent to it.

Of course if your game follows a regular grid throughout and has no overlapping actors you're fine.

Re: Alternative to CollisionFree - Collision Free From Actor

PostPosted: Fri Mar 04, 2011 8:03 pm
by lcl
AnarchCassius wrote:This other method is very nice for adjusting by object type but it has a major limitation, it's only scanning the top-most pixel at those exact coords. You won't know what's underneath or directly adjacent to it.

Of course if your game follows a regular grid throughout and has no overlapping actors you're fine.

Oh, I didn't know about that... :P

Re: Alternative to CollisionFree - Collision Free From Actor

PostPosted: Sat Mar 05, 2011 2:50 am
by Bee-Ant
Nice. good job :)

Re: Alternative to CollisionFree - Collision Free From Actor

PostPosted: Sun Mar 06, 2011 11:53 am
by lcl
Bee-Ant wrote:Nice. good job :)

Thanks!

Re: Alternative to CollisionFree - Collision Free From Actor

PostPosted: Sun Mar 06, 2011 3:03 pm
by Hblade
Wouldn't int temp need to be char temp, because I seen you used strcmp, which is string comparing O.o Int's dont handle strings right? xD

Re: Alternative to CollisionFree - Collision Free From Actor

PostPosted: Sun Mar 06, 2011 3:40 pm
by lcl
Hblade wrote:Wouldn't int temp need to be char temp, because I seen you used strcmp, which is string comparing O.o Int's dont handle strings right? xD

Lol dude. You didn't understand anything about that line.. xD
First thing is that strcmp(); returns int.
Second, my strcmp was inside brackets and there was ! = 0.
That's why if strcmp returns 0 temp is 0 so you're not collision free.
If strcmp returns anything else, temp will be 1. :)

Re: Alternative to CollisionFree - Collision Free From Actor

PostPosted: Fri Aug 26, 2011 1:49 am
by Jagmaster
So, if I understand correctly, you can use this instead of Collisionfree in Game a Gogo's collision example, but, I can add other actors that won't interfere with the collision? If this is true, I ought to start figuring out how to use this!

@Gag: If this is the answer to the question I just asked you, Sorry for buggin' you :lol:

Re: Alternative to CollisionFree - Collision Free From Actor

PostPosted: Tue Aug 30, 2011 6:22 am
by lcl
Jagmaster wrote:So, if I understand correctly, you can use this instead of Collisionfree in Game a Gogo's collision example, but, I can add other actors that won't interfere with the collision? If this is true, I ought to start figuring out how to use this!

@Gag: If this is the answer to the question I just asked you, Sorry for buggin' you :lol:

Yeah, that was just what I did this for.
There is only one limitation.. The function uses GE's getactor(x,y) function and it just checks the actor on top, with the littlest zDepth, so if you have any actor on top of the land, it will mess up. :P
I've tried to find a way to solve that but it's really difficult because I'd need to use something else than getactor() :P

Re: Alternative to CollisionFree - Collision Free From Actor

PostPosted: Tue Aug 30, 2011 2:19 pm
by Game A Gogo
if you check which way an actor is moving, plus it's relative position with say the land, you can determine where he is hitting.

Player hits Ground on top, GetAllActorsInCollision event triggered...
Code: Select all
double phw=player.width*.5,phh=player.height*.5;
double chw=collide.width*.5,chh=collide.height*.5;
if(player.x+phw>collide.x-chw&&player.x-phw<collide.x+chw)
{
    if(player.yvelocity-collide.yvelocity>0)
    {
         //Player is colliding on top of collide
     }
     else if(player.yvelocity-collide.yvelocity<0){//player is colliding on bottom of collide}
}
else if(player.y+phh>collide.y-chh&&player.y-phh<collide.y+chh)
{

    if(player.xvelocity-collide.yvelocity>0)
    {
         //Player is colliding on left side of collide
     }
     else if(player.xvelocity-collide.yvelocity<0){//player is colliding on right side of collide}
}


This is just something I am thinking about....

Re: Alternative to CollisionFree - Collision Free From Actor

PostPosted: Tue Aug 30, 2011 2:22 pm
by Jagmaster
lcl wrote:
There is only one limitation.. The function uses GE's getactor(x,y) function and it just checks the actor on top, with the littlest zDepth, so if you have any actor on top of the land, it will mess up. :P
I've tried to find a way to solve that but it's really difficult because I'd need to use something else than getactor() :P


By top, did you mean y coordinates or zdepth?

Edit: I'm pretty sure you meant y coordinates

Re: Alternative to CollisionFree - Collision Free From Actor

PostPosted: Tue Aug 30, 2011 2:26 pm
by lcl
Jagmaster wrote:
lcl wrote:...The function uses GE's getactor(x,y) function and it just checks the actor on top, with the littlest zDepth...


By top, did you mean y coordinates or zdepth?

Edit: I'm pretty sure you meant y coordinates

As I said, zDepth.
:D

Re: Alternative to CollisionFree - Collision Free From Actor

PostPosted: Tue Aug 30, 2011 2:27 pm
by lcl
Game A Gogo wrote:if you check which way an actor is moving, plus it's relative position with say the land, you can determine where he is hitting.

Player hits Ground on top, GetAllActorsInCollision event triggered...
Code: Select all
double phw=player.width*.5,phh=player.height*.5;
double chw=collide.width*.5,chh=collide.height*.5;
if(player.x+phw>collide.x-chw&&player.x-phw<collide.x+chw)
{
    if(player.yvelocity-collide.yvelocity>0)
    {
         //Player is colliding on top of collide
     }
     else if(player.yvelocity-collide.yvelocity<0){//player is colliding on bottom of collide}
}
else if(player.y+phh>collide.y-chh&&player.y-phh<collide.y+chh)
{

    if(player.xvelocity-collide.yvelocity>0)
    {
         //Player is colliding on left side of collide
     }
     else if(player.xvelocity-collide.yvelocity<0){//player is colliding on right side of collide}
}


This is just something I am thinking about....

Nice code but won't work with tile actors.. :P

Re: Alternative to CollisionFree - Collision Free From Actor

PostPosted: Tue Aug 30, 2011 2:30 pm
by Jagmaster
Hmm, too bad there isn't a variable to check zdepth. Unless you assigned zdepth to a variable and then checked that, but that would be rather pointless.

Re: Alternative to CollisionFree - Collision Free From Actor

PostPosted: Tue Aug 30, 2011 2:33 pm
by lcl
Jagmaster wrote:Hmm, too bad there isn't a variable to check zdepth. Unless you assigned zdepth to a variable and then checked that, but that would be rather pointless.

I thought of that too, but then realised that it won't help me because there isn't getactor(x, y, z) -function :P

EDIT:
I also tried to create an actor with animation of 1 pixel with VisibilityState() on DONT_DRAW_ONLY to the location to be checked and to check AllActorsInCollision() on that actor and after all is done, destroy it but that didn't work eiter. :P