Perfect collision exemple

Post here your demos and examples with the source files.
Forum rules
Always post the games with a screenshot.
The file must have the ged and data files (complete game source)
Use the forum attachment to post the files.
It is always better to use the first post to put the game files

Re: Perfect collision exemple

Postby lverona » Wed May 02, 2012 6:53 pm

Thanks to attentive help from skydereign, we have corrected a small but annoying bug in the code which made the actor get stuck in the ceiling at times. The problem is depicted here. The solution is explained there, but I have already corrected it in my commented code above: viewtopic.php?f=6&t=9992&start=15#p84257

All that it takes is to put yvelocity=0; after the if-else clause that checks for the ceiling. Now, no matter how fast you jump, there is no getting stuck.

The code gets better and better! ;)
lverona
 
Posts: 221
Joined: Tue Apr 24, 2012 11:54 am
Score: 1 Give a positive score

Re: Perfect collision exemple

Postby happyjustbecause » Wed May 02, 2012 11:31 pm

lverona wrote:I am now thinking over - how to work moving platforms? I haven't tried horizontal platforms, but with vertically moving platform there is a following problem: when the platform is moving DOWN and you are jumping on it from top, then the player never lands on the platform, but keeps touching it, then being pushed back, then falling and touching it again, then pushed back. The only way when the player can actually land on the vertically moving platform is when it moves UP.

This basically brings up the need for a certain function that would recognise the collision with an object, but not act as an actual collision. Meaning that one can have areas defined that would react to the player touching them, but at the same time being CollisionState disabled.

If there is such a function, I would really like to know, since it is crucial for a CollisionFree approach, otherwise it becomes very difficult to make the player interact with the environment other than bumping into it.

Here's an example: I want to pass a wire frame and by that action trigger a sound.
With a PhysicalReponse approach I can do this by just registering a collision. Not issuing a Physical Reponse I play a sound.
With a CollisionFree approach I cannot really do this. If I set wire frame to CollisionState=DISABLE, then it simply ignores any collision event at all.

So this is the fundamental problem here which needs a solution ;)


So there isn't currently a way to do something like you explained (wire frame)? That seems to be a large issue, what do you think of this collision method skydereign?

I mentioned this problem in one of the many topics about this method that have popped up.


Do you think this is a good method for collisions, it at least looks very nice to me, but if there are large problems with it, I don't know if I should use this one over another one I could maybe use. I want to rework the collision method I have, but I want to use the best one possible, at least the best one at my current skill level.
For small creatures such as we the vastness is bearable only through love.
-Carl Sagan

Night Knight Development Thread
User avatar
happyjustbecause
 
Posts: 267
Joined: Tue Jul 26, 2011 3:10 pm
Location: Frazier Park, Ca
Score: 15 Give a positive score

Re: Perfect collision exemple

Postby skydereign » Thu May 03, 2012 12:32 am

happyjustbecause wrote:So there isn't currently a way to do something like you explained (wire frame)? That seems to be a large issue, what do you think of this collision method skydereign?

That problem is the reason I'd never use this method in my games. It works great for simple platformers, but it prohibits quite a few ways of making your game more interactive. There are as I mentioned some ways around the problem, but none of them I have found acceptable.

happyjustbecause wrote:Do you think this is a good method for collisions, it at least looks very nice to me, but if there are large problems with it, I don't know if I should use this one over another one I could maybe use. I want to rework the collision method I have, but I want to use the best one possible, at least the best one at my current skill level.

I prefer using a bounding box actor, and all that that entails. It isn't perfect though, no method so far is. So you really have to compare the problems with each method and decide which is best for your game. If though I can get the CollisionFree2 function working, then we would be able to bypass the one major problem with the CollisionFree method.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Perfect collision exemple

Postby phyzix5761 » Thu May 03, 2012 3:36 am

Having a problem with this method. When the top of the player hits the bottom of a block his xvelocity becomes 0. I don't want this to be the case because I am not working with gravity. I am working on a top down game. How can I change this?
phyzix5761
 
Posts: 261
Joined: Sun Feb 27, 2011 4:28 am
Score: 18 Give a positive score

Re: Perfect collision exemple

Postby lverona » Thu May 03, 2012 8:15 am

happyjustbecause, I can tell you how I am currently working around this problem.

I am using a wire frame and I put it on the same level as the ground (or a platform or whatever floor), so that I make sure the player touches it, but does not notice it. In the script - if this is a one time thing - I put a command to set the wire frame to be CollisionState disabled, and then put in the code I need to have.

This works for most things. What it does not work for is for the exact case of a vertically moving platform, because you would want a wire frame sticking out of the platform a couple of pixels and 1. Be CollisionState disabled, so that the player does not bump into it 2. Receive a Collision event nonetheless.

So far I still think this is a very good approach, much more efficient to be used for a player actor than the Physical Response. skydereign said he'll put together a special function for this. Let's wait and see how that works.
lverona
 
Posts: 221
Joined: Tue Apr 24, 2012 11:54 am
Score: 1 Give a positive score

Re: Perfect collision exemple

Postby lverona » Thu May 03, 2012 8:16 am

phyzix5761 wrote:Having a problem with this method. When the top of the player hits the bottom of a block his xvelocity becomes 0. I don't want this to be the case because I am not working with gravity. I am working on a top down game. How can I change this?


You probably mean yvelocity.
Simple - do not set it to 0.
lverona
 
Posts: 221
Joined: Tue Apr 24, 2012 11:54 am
Score: 1 Give a positive score

Re: Perfect collision exemple

Postby phyzix5761 » Thu May 03, 2012 10:36 am

No I actually mean xvelocity. Give it a try. Whenever the actor hits the bottom of a block he can't move left or right.
phyzix5761
 
Posts: 261
Joined: Sun Feb 27, 2011 4:28 am
Score: 18 Give a positive score

Re: Perfect collision exemple

Postby lverona » Thu May 03, 2012 11:28 am

Show us your code. Seems you've made a mistake somewhere.
There is only one line I can see that puts xvelocity to 0 and it is this one:

//if ceiling is too low, we cannot move
else if(CollisionFree("Event Actor",x+xvelocity,y-5)==0)xvelocity=0;

And this looks for a low ceiling, not just hitting the bottom.
lverona
 
Posts: 221
Joined: Tue Apr 24, 2012 11:54 am
Score: 1 Give a positive score

Re: Perfect collision exemple

Postby phyzix5761 » Thu May 03, 2012 12:01 pm

Yep that's the line. I tried to change it but it takes away the capability to stop at walls. Any idea how to change this while still retaining capability?
phyzix5761
 
Posts: 261
Joined: Sun Feb 27, 2011 4:28 am
Score: 18 Give a positive score

Re: Perfect collision exemple

Postby lverona » Thu May 03, 2012 12:30 pm

This line does not contain the gravity code. I don't see that you need to change it at all. If you want to take away the gravity, just don't do this: yvelocity+=0.16
lverona
 
Posts: 221
Joined: Tue Apr 24, 2012 11:54 am
Score: 1 Give a positive score

Re: Perfect collision exemple

Postby Game A Gogo » Thu May 03, 2012 7:05 pm

if it helps anyone, I'd never use this type of collision method for my games :P
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: Perfect collision exemple

Postby lverona » Thu May 03, 2012 8:17 pm

Well I find it to be a more efficient method when it comes to using it on a player actor and I am glad I got active around it. If skydereign writes a function to handle collisions when using this method, I think it would be a very good step and would make lots of things easier as well as more efficient in Game Editor.
lverona
 
Posts: 221
Joined: Tue Apr 24, 2012 11:54 am
Score: 1 Give a positive score

Re: Perfect collision exemple

Postby skydereign » Thu May 03, 2012 8:22 pm

Well, I'm not going to change the collisions and how they are handled. What I'm going to try to do (haven't started) is make a CollisionFree2 function that accepts a list of actors. That way you can check if the actor isn't colliding with any actors specified in the list. Actually altering the collision state handling would be a bad idea. Anyway, that'll probably be released with 1.5 assuming I can get it working.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Perfect collision exemple

Postby lverona » Fri May 04, 2012 6:19 am

Well I don't want you to change anything but just add this one function. By the way, can I ask how do you envision the workings of that function? I just want to make sure I understand in what way it corrects the problem.
lverona
 
Posts: 221
Joined: Tue Apr 24, 2012 11:54 am
Score: 1 Give a positive score

Re: Perfect collision exemple

Postby skydereign » Fri May 04, 2012 1:59 pm

Code: Select all
int CollisionFree2(char* clonename, int x, int y, char* actorList ...);

So you could use it like this.
Code: Select all
if(CollisionFree2("Event Actor", x, y, "ground", "walls", "other")==1)
{
    // do something
}

Essentially you can specify the actors you want to check if you are colliding with. The setup in the source isn't quite opportune, but it might still be manageable.

-Edit
Well it seems varargs doesn't work quite as nicely as I thought. So, I may end up having to specify only a single actor per call. Then the user could write a wrapper that uses an array of strings, to call the function. Less desirable but, I want to keep all of the gE function relatively uniform.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

PreviousNext

Return to Game Demos

Who is online

Users browsing this forum: No registered users and 1 guest

cron