PDA

View Full Version : Collision Mission! (Part 1: Hill Detection)


reuben2011
02-19-2011, 06:51 PM
So anyway, since collision detection is a main subject on Alice, I thought it would be a good idea to start a miny project involving creating engines/demos that showcase collision detection and other physics-related events.

Anyways, I made this Alice world that is able to detect hills and allow objects to move smoothly over them.

Anyways, fyi, I used zonedabone's collision detection engine, figuring it had a lot of things on it that I wouldn't need to recreate, like the object arrays, some variables, the maintenance script, etc. So zonedabone: thanks a lot! Also, I added to documentation (aka comments), including the parts that zonedabone coded, so hopefully people can understand it a little better.

Anyways, feel free to use the code, or implement the world into your own game, as long as you give me credit :D I am open to suggestions and I already have a "to-do" list that can be seen in the documentation in the world. I'll be editing this original post to add any updates or new versions.


PS Zonedabone: Feel free to "upgrade" the program in any way with your awesomeness (there are some other maintenance issues). :p

EDIT: Just realized this is my 100th post! Woot! XD

EDIT2: Ok, just added the world! Feel free to look! Don't mind the file name, I couldn't think of a good name. lol Btw, if you want the hills to look realistic, you can just change the sphere's texture to the ground's. Also, you can add more hills simply by adding more spheres (that are sunken into the ground) into the hill array.

Notes
-As of right now, only hills in the shape of perfect semi-spheres work. I am working on "shallow hill.s"
-The ball is going down via a loop that moves the ball down. You can try to tweak the length and time parameters so get a smoother effect. On one extreme, it will appear as if the ball is vibrating and on the other extreme, the ball might just "fall" off the semi-sphere. You can interpret that as a bug, or gravity, whatever you wish. =D

To-Do List
-Shallow hills (not just semi-spheres)
-Calculating slope of hill to allow things to rotate accordingly (such as a car driving on it. You wouldn't want the car to be parallel to the ground the whole time.)
-Implementing offset variable since some objects have a "center" that touches the ground
-Allow main object to move correctly at hill intersections (like if we put the two hills together such that parts of the hill are within each other. Would make for good "rolling hills" effect.)
-Change main object to an array of main object's'
-Let me know!

arty-fishL
02-19-2011, 06:59 PM
Zenteos terrain builder had perfect collision on its surface:
on this thread (http://www.alice.org/community/showthread.php?t=4155)

100 posts, first benchmark. :):):)

reuben2011
02-21-2011, 04:54 AM
Interesting, I'll take a look at the terrain builder once I'm off from vacation and I have access to my laptop with Alice on it. I want to see how the collision detection works on it. ^_^

Anyways, I should have the world up by Monday. Well the positives with this, (as opposed to terrain builder), is that it would be a lot quicker of you want to work with hills that were in the shape of a sphere cut along some horizontal axis (semi-sphere or less.) It'll make sense when you guys see it. Plus, I didn't use any heightmaps or anything (I want to see how that works in terrain builder though), just some algebra. I basically worked off of the formula for the graph of circle since a sphere is basically a circle revolved about a plane.

Dameria
02-21-2011, 10:24 AM
So anyway, since collision detection is a main subject on Alice, I thought it would be a good idea to start a miny project involving creating engines/demos that showcase collision detection and other physics-related events.

Anyways, I made ...

Anyways, I'm on "vacation" [...]

Anyways, fyi, I used [...]

Anyways, feel free [...]

You use the word "anyways" a lot haha. Well I'm looking forward to seeing how you do your version of collision detection with hills.

reuben2011
02-21-2011, 09:51 PM
You use the word "anyways" a lot haha. Well I'm looking forward to seeing how you do your version of collision detection with hills.

I noticed that (the "anyways.") Haha. Anyways, (lol) I just added the file. See the original post for updates. Look under "edit2", "notes", "to-do list", and "attached files" for the stuff I just added. Enjoy! :D

reuben2011
02-22-2011, 04:08 PM
Sorry for double posting but... has anyone taken a look at the world that I posted?

reuben2011
02-28-2011, 11:55 AM
No comments? (^bump)

AJMansfield
03-07-2011, 11:22 AM
the system way up near the top w/ the hills, if the circle formulas were replaced with functions containing those formulas (so we never actually see the formula, and hence have less chance of messing it up), the code would become much more maintainable.

reuben2011
03-07-2011, 11:46 AM
the system way up near the top w/ the hills, if the circle formulas were replaced with functions containing those formulas (so we never actually see the formula, and hence have less chance of messing it up), the code would become much more maintainable.

I'll try to clean up the code for the next version that I make.

David B
03-07-2011, 11:47 AM
I don't see why collision detection is so exciting. It is very easy to do.
:confused::confused::confused::confused::confused: :confused::confused::confused::confused::confused:

reuben2011
03-07-2011, 12:14 PM
I don't see why collision detection is so exciting. It is very easy to do.
:confused::confused::confused::confused::confused: :confused::confused::confused::confused::confused:

Have you viewed the program? If you look at my code, you will see that this program is more complicated than regular collision detection. I had to use a deviation of both the circle formula ((x-h)^2 + (y-k)^2 = r^2) and the Pythagorean theorem (a^2 + b^2 = c^2) in order to move a object smoothly over a spherically shaped object.

arty-fishL
03-10-2011, 05:03 PM
why couldn't you just use

y = a COS( b x ) :confused:

where
a is the height (or amplitude) of the hill
b is the width (or period) of the hill
x is the distance to the centre of the base of the hill

and y is the resulting height of the colliding object relative to the hill

EDIT - that would be for the hill object in the object gallery, for a different shape of hill you could calculate it like a basic parabola.

reuben2011
03-10-2011, 11:52 PM
why couldn't you just use

y = a COS( b x ) :confused:

where
a is the height (or amplitude) of the hill
b is the width (or period) of the hill
x is the distance to the centre of the base of the hill

and y is the resulting height of the colliding object relative to the hill

EDIT - that would be for the hill object in the object gallery, for a different shape of hill you could calculate it like a basic parabola.

Well, the curvature of the hill doesn't exactly fit a cosine curve I believe. Would you like to edit my example and post your own. Maybe then I can understand. Also, Alice doesn't have an built-in function for calculating the "x" in your equation.