Author |
Message |
tjmoore1993
|
Posted: 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. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
DtY
|
Posted: 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. |
|
|
|
|
|
corriep
|
Posted: 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. |
|
|
|
|
|
tjmoore1993
|
Posted: 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. |
|
|
|
|
|
zero-impact
|
Posted: 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. |
|
|
|
|
|
tjmoore1993
|
Posted: Sat May 16, 2009 10:04 am Post subject: Re: Best way to detect collision |
|
|
I want to achieve this
But I want it to look like this
|
|
|
|
|
|
Dusk Eagle
|
Posted: 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). |
|
|
|
|
|
tjmoore1993
|
Posted: 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... |
|
|
|
|
|
Sponsor Sponsor
|
|
|
tjmoore1993
|
Posted: Sat May 16, 2009 3:59 pm Post subject: RE:Best way to detect collision |
|
|
I have solved the problem...
|
|
|
|
|
|
zero-impact
|
Posted: Sat May 16, 2009 4:14 pm Post subject: RE:Best way to detect collision |
|
|
Mind sharing what you did? Just explaining it? |
|
|
|
|
|
tjmoore1993
|
Posted: 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. |
|
|
|
|
|
corriep
|
Posted: Sat May 16, 2009 8:29 pm Post subject: RE:Best way to detect collision |
|
|
K.I.S.S
works every time |
|
|
|
|
|
tjmoore1993
|
Posted: Sat May 16, 2009 9:35 pm Post subject: Re: Best way to detect collision |
|
|
Someone said that there would be flickering problems
I did not get a flicker of any sort I even added virtual lag to the program and no flicker. |
|
|
|
|
|
corriep
|
Posted: 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? |
|
|
|
|
|
Dusk Eagle
|
Posted: 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. |
|
|
|
|
|
|