Computer Science Canada

Best way to detect collision

Author:  tjmoore1993 [ Fri May 15, 2009 8:05 pm ]
Post subject:  Best way to detect collision

I have this game called Fantastic Story, it includes a lot of features. One of the features I am working on at the moment is traveling. When my character walks I want it so that he is always on the GROUND.

I want to have it so when my character comes across a slope it doesn't go straight through it but instead climb up that slope. If any help can be given on this I would gratefully appreciate it.

Author:  DtY [ Fri May 15, 2009 9:12 pm ]
Post subject:  RE:Best way to detect collision

The easiest way in Turing is probably to check the colour of the pixel where you're trying to move to.

Author:  corriep [ Fri May 15, 2009 9:16 pm ]
Post subject:  Re: Best way to detect collision

This shouldn't be hard, you need to know 2 things:
  • The (x, y) coords of the player
  • The two (x, y) coords on the slope
After that its just a matter of checking if the player's x value is between the 2 of the slope (meaning he is on the slope) and then setting the y-value to the intercept of the player's x and the line.

Author:  tjmoore1993 [ Fri May 15, 2009 9:40 pm ]
Post subject:  Re: Best way to detect collision

corriep @ Fri May 15, 2009 9:16 pm wrote:
This shouldn't be hard, you need to know 2 things:
  • The (x, y) coords of the player
  • The two (x, y) coords on the slope
After that its just a matter of checking if the player's x value is between the 2 of the slope (meaning he is on the slope) and then setting the y-value to the intercept of the player's x and the line.


The problem there is I do not want to define every piece of land.

Author:  zero-impact [ Fri May 15, 2009 10:47 pm ]
Post subject:  RE:Best way to detect collision

Ok so how are you actually storing the data for the landscape? The method you use for collision detection will depend primarily on that.

Author:  tjmoore1993 [ Sat May 16, 2009 10:04 am ]
Post subject:  Re: Best way to detect collision

I want to achieve this

Posted Image, might have been reduced in size. Click Image to view fullscreen.

But I want it to look like this


Posted Image, might have been reduced in size. Click Image to view fullscreen.

Author:  Dusk Eagle [ Sat May 16, 2009 3:33 pm ]
Post subject:  Re: Best way to detect collision

Without programming this entire thing myself, here's a general overview of one way I've thought of to do it with whatdotcolor. I know whatdotcolor is scorned upon, but this is a simple way of doing things in this case IMO. A more experienced programmer might point out a better way.

In between the time when you clear the screen and the time when the background is drawn to the screen, draw a picture which outlines the ground and walls of your map area. Then do collision detection (using whatdotcolor) - if any of your character is going through the ground, elevate him to the top of the ground, and if any of your character is touching a wall, do not let the character move in that direction. When that is done, draw the real background on top of your collision background. I'm a bit worried that this way might cause flickering, but I'm not about to code all this just to test that (It'd be easier to do it this way if Turing supported multiple run windows, which I don't think it does).

Author:  tjmoore1993 [ Sat May 16, 2009 3:53 pm ]
Post subject:  Re: Best way to detect collision

Dusk Eagle @ Sat May 16, 2009 3:33 pm wrote:
Without programming this entire thing myself, here's a general overview of one way I've thought of to do it with whatdotcolor. I know whatdotcolor is scorned upon, but this is a simple way of doing things in this case IMO. A more experienced programmer might point out a better way.

In between the time when you clear the screen and the time when the background is drawn to the screen, draw a picture which outlines the ground and walls of your map area. Then do collision detection (using whatdotcolor) - if any of your character is going through the ground, elevate him to the top of the ground, and if any of your character is touching a wall, do not let the character move in that direction. When that is done, draw the real background on top of your collision background. I'm a bit worried that this way might cause flickering, but I'm not about to code all this just to test that (It'd be easier to do it this way if Turing supported multiple run windows, which I don't think it does).


I do not need to worry about anti - flicker. I have a work around that is more efficient then View.Update and executes faster. Also I have tried "whatdotcolour". The problem with "whatdotcolour" is that you can't use it in my case because of my updating method.

I can't share my code because it has taken a while to write it and I am handing this in as a project.

Also I think I might just make flat grounds...

Author:  tjmoore1993 [ Sat May 16, 2009 3:59 pm ]
Post subject:  RE:Best way to detect collision

I have solved the problem...

Posted Image, might have been reduced in size. Click Image to view fullscreen.

Author:  zero-impact [ Sat May 16, 2009 4:14 pm ]
Post subject:  RE:Best way to detect collision

Mind sharing what you did? Just explaining it?

Author:  tjmoore1993 [ Sat May 16, 2009 5:35 pm ]
Post subject:  RE:Best way to detect collision

I replaced the pictures with flat ground so I only need to define a Y co-ordinate.

Simple fix and it is easier to maintain. Smile

Author:  corriep [ Sat May 16, 2009 8:29 pm ]
Post subject:  RE:Best way to detect collision

K.I.S.S

works every time

Author:  tjmoore1993 [ Sat May 16, 2009 9:35 pm ]
Post subject:  Re: Best way to detect collision

Someone said that there would be flickering problems


Posted Image, might have been reduced in size. Click Image to view fullscreen.

I did not get a flicker of any sort I even added virtual lag to the program and no flicker.

Author:  corriep [ Sat May 16, 2009 9:57 pm ]
Post subject:  RE:Best way to detect collision

Dude, your an amazing artist to make those background what program did you use?

Author:  Dusk Eagle [ Sat May 16, 2009 10:14 pm ]
Post subject:  Re: Best way to detect collision

I only said there might be flickering problems if you followed my way of doing things. Since you've made the ground flat, I don't see why there'd be any problems.

PS: Once you've received a grade on your summative, can you release your improved version of View.Update? I'm quite interested to see what you did.

Author:  SJ [ Sun May 17, 2009 7:18 am ]
Post subject:  RE:Best way to detect collision

haha, a maplestory spinoff. I did something like this in java some time ago. At the time I stored all the floor and wall information in vectors. can't say that's the best approach..

Author:  tjmoore1993 [ Sun May 17, 2009 7:36 am ]
Post subject:  Re: RE:Best way to detect collision

corriep @ Sat May 16, 2009 9:57 pm wrote:
Dude, your an amazing artist to make those background what program did you use?


The images used in the game are property of Wizet. I do not take credit for drawing them although I could with my Waccom which is broken because I jabbed it too hard when I slipped and fell.

Author:  tjmoore1993 [ Sun May 17, 2009 7:38 am ]
Post subject:  Re: RE:Best way to detect collision

tjmoore1993 @ Sun May 17, 2009 7:36 am wrote:
corriep @ Sat May 16, 2009 9:57 pm wrote:
Dude, your an amazing artist to make those background what program did you use?


The images used in the game are property of Wizet. I do not take credit for drawing them although I could with my Waccom which is broken because I jabbed it too hard when I slipped and fell.



@The post above me

I helped emulate Maplestory with team Odin, I programmed the database and did some of the parsing.


: