Page 1 of 1
Collision detection perfection
Posted:
Sat Aug 13, 2011 7:30 pm
by ikarus
A game I'm working on requires a lot of bouncing sprites, the arena is just a vector image I made with a width of 4 pixels. I noticed that as the speed of the sprites increases, they start flying out of the arena, or if the player hits a pretty acute angle they'll fly out sometimes too.
Does anybody have any good rules of hand when it comes to collision detection? Should I just forgo a physical response and just change the direction of each actor hitting the arena?
Thanks^^
Re: Collision detection perfection
Posted:
Sat Aug 13, 2011 10:16 pm
by skydereign
At that point you'll probably need to create your own collision detection system. You can use CollisionFree and possible getactor for this. But if you are using collision events and PhysicalResponse, you have to have the max speed be less then the width of the tile. That way no matter what speed they come at, the actor can never pass half of the tile. This should also apply to acute angles, just make sure to cap the bounce velocities in the collision event. If you are looking for alternatives to collision events, there are several users that posted their own perfect collision demos.
Re: Collision detection perfection
Posted:
Sun Aug 14, 2011 2:33 pm
by Jagmaster
I have a question regarding Collision free. How do you tell an actor to do an event if it is not colliding with a certain actor? When I try, it wants to check collision with every actor. Is there any variable or argument that can be placed in between the parentheses of Collfree in order to do this?
Re: Collision detection perfection
Posted:
Sun Aug 14, 2011 11:09 pm
by ikarus
Perfect answer! You've given me a lot to to think about, I'll start messing with the dimensions and speeds. Kinda curious about jagmaster's question though lol
Re: Collision detection perfection
Posted:
Mon Aug 15, 2011 4:12 am
by Game A Gogo
Jagmaster wrote:Is there any variable or argument that can be placed in between the parentheses of Collfree in order to do this?
Unfortunately no. You could use GetAllAcotrsInCollision (or something) so it returns all actor colliding with the current one, but then you can't use the X and Y offset trick. I suggest maybe creating an almost invisible dummy (Most likely behind everything, even the back ground, collision still happens if actors are overlapped). Then you can set the position of the dummy collision and use the get all actors in collision. If you need help with the function, simply go into Help -> Documentation -> Scripting -> Script Reference then you can search for the function
Re: Collision detection perfection
Posted:
Mon Aug 15, 2011 5:23 pm
by ikarus
I'm on linux and I don't see the documentation option in the help menu? Is the linux version using an older ui? by the way has anyone ever made an effort to create a wiki for game editor?
Re: Collision detection perfection
Posted:
Mon Aug 15, 2011 9:13 pm
by Game A Gogo
GE wiki does or did exist... Rarely used. Also documentation should be in your GE folder GameEditor/Docs/index.html
Re: Collision detection perfection
Posted:
Tue Aug 16, 2011 5:41 am
by skydereign
I've been trying to work on the wiki, and in a month when I'm done working with Omni-arts I'll have the time to continue making it worth looking at.
Re: Collision detection perfection
Posted:
Sun Aug 21, 2011 4:31 am
by ikarus
Just curious, anyone have a good technique for finding the point of the collision?
Re: Collision detection perfection
Posted:
Sun Aug 21, 2011 8:30 am
by ikarus
Nevermind, I found out! Woooooo!
- Code: Select all
int xx;
int yy;
int i;
int xvol = xvelocity;
int yvol = yvelocity;
while(i < 1000){
xx += xvol;
yy += yvol;
if(xx >= width*0.5 || xx <= width*0.5*-1){
xx += -10*(xvol*xvol)/abs(xvol)/xvol;
i = 1000;
}
if(yy >= height*0.5 || yy <= height*0.5*-1){
yy += -10*(yvol*yvol)/abs(yvol)/yvol;
i = 1000;
}
i++;
}
To get the exact position just add tha actor's real cordinates.
- Code: Select all
xx += x;
yy += y;
The "xx += -10*(xvol*xvol)/abs(xvol)/xvol;" and "yy += -10*(yvol*yvol)/abs(yvol)/yvol;" aren't needed, that's just something I used to find the coordinates to create my particles. I set the position back 10 pixels from the hit cause the thing it was hitting was messing with their look lol. Just included them to show how you may want to fine tune it using some nice math. I have the loop end at 1000 because I found that sometimes ge bugs and the loop never ends, not very often, so I made a failsafe. Plus I doubt you'll ever need a collision point that'll be beyond that. But if you do, just change the limits. Don't know how fast this is, but it works fine for me
Enjoy ^-^
Re: Collision detection perfection
Posted:
Mon Aug 22, 2011 4:42 am
by ikarus
Actually I should mention that it's not 100% perfect since it uses the velocities, so if something hits the head of the character while your moving right then it'll think the collision is directly to the right. I could think of a way to do it perfect but that would probably mess with the colliding actors x/y and width and height and won't work for large actors that say make the level like tiles. Got's me wondering how about doing perfect collision points though