Alternative to CollisionFree - Collision Free From Actor!

You must understand the Game Editor concepts, before post here.

Alternative to CollisionFree - Collision Free From Actor!

Postby lcl » Fri Mar 04, 2011 7:35 pm

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!
Attachments
Alternative_CollisionFree.zip
Download the example file here
(264.75 KiB) Downloaded 238 times
Last edited by lcl on Fri Mar 04, 2011 8:00 pm, edited 1 time in total.
Having a temporary break of most GE related things. I'll be back.
User avatar
lcl
 
Posts: 1908
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 202 Give a positive score

Re: Alternative to CollisionFree - Collision Free From Actor

Postby AnarchCassius » Fri Mar 04, 2011 7:58 pm

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.
AnarchCassius
 
Posts: 55
Joined: Sat Jan 29, 2011 1:33 am
Score: 6 Give a positive score

Re: Alternative to CollisionFree - Collision Free From Actor

Postby lcl » Fri Mar 04, 2011 8:03 pm

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
Having a temporary break of most GE related things. I'll be back.
User avatar
lcl
 
Posts: 1908
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 202 Give a positive score

Re: Alternative to CollisionFree - Collision Free From Actor

Postby Bee-Ant » Sat Mar 05, 2011 2:50 am

Nice. good job :)
User avatar
Bee-Ant
 
Posts: 3695
Joined: Wed Apr 11, 2007 12:05 pm
Location: Can bee found antywhere
Score: 208 Give a positive score

Re: Alternative to CollisionFree - Collision Free From Actor

Postby lcl » Sun Mar 06, 2011 11:53 am

Bee-Ant wrote:Nice. good job :)

Thanks!
Having a temporary break of most GE related things. I'll be back.
User avatar
lcl
 
Posts: 1908
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 202 Give a positive score

Re: Alternative to CollisionFree - Collision Free From Actor

Postby Hblade » Sun Mar 06, 2011 3:03 pm

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
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4365
Joined: Fri Dec 08, 2006 11:14 pm
Score: 168 Give a positive score

Re: Alternative to CollisionFree - Collision Free From Actor

Postby lcl » Sun Mar 06, 2011 3:40 pm

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. :)
Having a temporary break of most GE related things. I'll be back.
User avatar
lcl
 
Posts: 1908
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 202 Give a positive score

Re: Alternative to CollisionFree - Collision Free From Actor

Postby Jagmaster » Fri Aug 26, 2011 1:49 am

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:
User avatar
Jagmaster
 
Posts: 802
Joined: Sun May 08, 2011 4:14 pm
Location: Not where you think.
Score: 67 Give a positive score

Re: Alternative to CollisionFree - Collision Free From Actor

Postby lcl » Tue Aug 30, 2011 6:22 am

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
Having a temporary break of most GE related things. I'll be back.
User avatar
lcl
 
Posts: 1908
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 202 Give a positive score

Re: Alternative to CollisionFree - Collision Free From Actor

Postby Game A Gogo » Tue Aug 30, 2011 2:19 pm

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

Re: Alternative to CollisionFree - Collision Free From Actor

Postby Jagmaster » Tue Aug 30, 2011 2:22 pm

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
User avatar
Jagmaster
 
Posts: 802
Joined: Sun May 08, 2011 4:14 pm
Location: Not where you think.
Score: 67 Give a positive score

Re: Alternative to CollisionFree - Collision Free From Actor

Postby lcl » Tue Aug 30, 2011 2:26 pm

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
Having a temporary break of most GE related things. I'll be back.
User avatar
lcl
 
Posts: 1908
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 202 Give a positive score

Re: Alternative to CollisionFree - Collision Free From Actor

Postby lcl » Tue Aug 30, 2011 2:27 pm

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
Having a temporary break of most GE related things. I'll be back.
User avatar
lcl
 
Posts: 1908
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 202 Give a positive score

Re: Alternative to CollisionFree - Collision Free From Actor

Postby Jagmaster » Tue Aug 30, 2011 2:30 pm

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.
User avatar
Jagmaster
 
Posts: 802
Joined: Sun May 08, 2011 4:14 pm
Location: Not where you think.
Score: 67 Give a positive score

Re: Alternative to CollisionFree - Collision Free From Actor

Postby lcl » Tue Aug 30, 2011 2:33 pm

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
Last edited by lcl on Tue Aug 30, 2011 2:36 pm, edited 1 time in total.
Having a temporary break of most GE related things. I'll be back.
User avatar
lcl
 
Posts: 1908
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 202 Give a positive score

Next

Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 0 guests