Alice Community

Alice Community (http://www.alice.org/community/index.php)
-   Works-In-Progress (http://www.alice.org/community/forumdisplay.php?f=14)
-   -   Collision detection engine (http://www.alice.org/community/showthread.php?t=3994)

zonedabone 02-26-2010 10:45 PM

Collision detection engine
 
2 Attachment(s)
Welcome to the collision engine! Please feel free to use this in your games, as long as you give me credit!

Required Sections:
[LIST][*]Collision method, and event calling it.[*]World variables.[*]All objects referenced to by the objects list.[*]A cylinder named "cylinder".[/LIST]Known Bugs:
[LIST][*]Main cylinder hovers. Fixed as of 1.1.[*]Cylinder might re-size erratically. Can be fixed by putting cylinders closer together.[*]Main cylinder appears to vibrate while against a wall. This is the location being corrected. It can be reduced by putting cylinders closer together.[/LIST]Todo:
[LIST][*]Add support for different types of obstacles. (i.e. squares, spheres, etc.)[*]Less memory intensive methods. This is to leave more memory with other methods.[*]Get a balanced time and distance for collision data setting. This will help to reduce vibration on the main cylinder, while hopefully not running the method too much. It is memory intensive to check every object![/LIST]Recommendations:
[LIST][*]The objects that you collide with can be invisible! Use Other objects for visuals, and leave the work to the cylinders![*]The program fixes collision data every quarter second. Setting the world variable "break" will override this, and cause the data to be refreshed immediately. This is good for when you change scenes.[/LIST]Current Version:
[ATTACH]2670[/ATTACH]

Current Engine(No other stuff):
[ATTACH]2671[/ATTACH]

Dameria 02-26-2010 10:55 PM

Wow, this is very nice and very smooth (although the coding doesn't really make sense to me, but hey, if it works then thats all that really matters! :D)

However, this is an [i]almost[/i] flawless engine. There is only 1 glitch that I have found so far, but it is a major one (sorta). Ok so you know there is a spot in top right that you can escape from the cylinder prison, but then go to the top left, once you are outside, to that gap that you can almost get into. If you wiggle around a bit, you find that you can somehow wiggle [b]over[/b] the gap, making you hover slightly, allowing you to get past the cylinders and the collision detection does not work from then on. (Maybe I should be a video game tester...)

zonedabone 02-26-2010 11:05 PM

Actually, I'm already working on a new engine that uses trig to calculate horizontal distance. Furthermore, you can just add another cylinder in that space. You know that you can move the cylinders, add more, and play as much as you want, so long as the list contains all of the cylinders? It's awesome!

Dameria 02-26-2010 11:11 PM

Yes, but if you run into a glitch like the one I did, the whole concept will be for nothing because the collision detection will not work anymore. If you add another cylinder there, then you may be able to do it in another part of the game.

zonedabone 02-26-2010 11:43 PM

Guess what? I added a method to the world. Every second, it runs what I call a "Maintenance script." It resets the vertical position of your cylinder! I can also add other things to it. I have it reset the positions of the others at the beginning, since they never move. Just remember that you can have as many of these as you want! I'm thinking of adding a side script that reduces the load on the main unit, though. I wouldn't be good to have 100 cylinders if 90 of them are obviously out of reach! Maybe this could be included in the maintenance script!

zonedabone 02-27-2010 12:01 AM

Breakthrough! The higher up on the events list an event is, the higher priority it is! That's great! I'll be sure to keep my collision there, and my maintenance at the bottom

Niteshifter 02-27-2010 12:06 AM

[QUOTE=zonedabone;17646]Guess what? I added a method to the world. Every second, it runs what I call a "Maintenance script." It resets the vertical position of your cylinder! I can also add other things to it. I have it reset the positions of the others at the beginning, since they never move. Just remember that you can have as many of these as you want! I'm thinking of adding a side script that reduces the load on the main unit, though. I wouldn't be good to have 100 cylinders if 90 of them are obviously out of reach! Maybe this could be included in the maintenance script![/QUOTE]

I might have an idea on how this could be achieved. Have the method find every object that is within a reasonable distance put into a "listen for" list at the beginning. Then after the maintenance script is run, it will iterate through the "listen for" list to remove objects out of range and add the objects within range (that is, if they are in the main list and not already in the "listen for" list to begin with). Then, have the collision detector use the "listen for" list instead of the main list.

zonedabone 02-27-2010 08:15 AM

I actually already was doing that, but thanks for the suggestion! Please spread the word! I believe that this is the smoothest and simplest collision engine out there!

King Gamer(gorit) 02-27-2010 03:09 PM

True
 
Ok, this works great except it only works ith cylinders and circle objects. It is however very simple which I give you props for. I will however continuw with my collision detection engine only because I like to have full control of what is hapening. I did see that you adressed the fact that methods are slower than functions. I will probably add your idea of only checking what is within 5 meters.

zonedabone 02-27-2010 03:31 PM

The best part is the two step filtering! the first step filters every 1/4 second, and does most of the work! The second filters the last couple things, and then just corrects it!

King Gamer(gorit) 02-27-2010 04:22 PM

Yeah
 
It is a really good system but I think if you used methods you could make sure it is working even faster. I wish however that I could use such a simple system for the skiing game I am making. My skiing game will need to figure out the side the collision ocured on then fall acording to the speed and direction. I like this though, but you should think about making this work wit iregular size objects
:D:D:DThis is my 111th post.:D:D:D

zonedabone 02-27-2010 06:16 PM

What do you mean by using methods? Calling methods takes time! Built in methods are what we call "inline" which means that the code is compiled in a way. Also, I've put the main event at the beginning, which gives it a higher priority! I do need to optomize the main code, however. I tried adding comments so people know what's going on, but that slows it down! So yes, there is work to be done, but I'm ready to do it!

jediaction 02-27-2010 06:39 PM

[QUOTE=Dameria;17634]Wow, this is very nice and very smooth (although the coding doesn't really make sense to me, but hey, if it works then thats all that really matters! :D)

However, this is an [I]almost[/I] flawless engine. There is only 1 glitch that I have found so far, but it is a major one (sorta). Ok so you know there is a spot in top right that you can escape from the cylinder prison, but then go to the top left, once you are outside, to that gap that you can almost get into. If you wiggle around a bit, you find that you can somehow wiggle [B]over[/B] the gap, making you hover slightly, allowing you to get past the cylinders and the collision detection does not work from then on. (Maybe I should be a video game tester...)[/QUOTE]

I dont get it either so it cant help me make cool games with collisoin. Sorry, but good job!!!!

zonedabone 02-27-2010 06:41 PM

It tests proximity, and then moves the main object accordingly. I'll try to make a version with comments, although it will run crazy slow with them there. :(

King Gamer(gorit) 02-27-2010 11:41 PM

All I Mean...
 
All I mean is that functions run faster no matter where the method is in the event area. Alice executes functions with a higher priority than any other methods. It is not always a necisary thing to do but if you do it it can create problems when hundreds of items are within the area it is in. It apears in your demo world that there is a bit of shaking.

zonedabone 02-28-2010 11:28 AM

There's a reason! There's less shaking with the cylinders clower together. Also, I use some things that aren't available in functions! I assure you that I've tackled every angle! Of course, there's a bit to work on with the order of the function.

jediaction 02-28-2010 11:41 AM

Can someone make an example of when an object is behing an object, it dissapears then appears again when its in front

Dameria 02-28-2010 11:49 AM

[QUOTE=jediaction;17750]Can someone make an example of when an object is behing an object, it dissapears then appears again when its in front[/QUOTE]

You could have just asked me jediaction, I will make one and then show you (it will require you to put every object in your world into an object list, so start doing that).

jediaction 02-28-2010 11:51 AM

WHAT KIND OF LIST! thats were im stuck

Dameria 02-28-2010 12:03 PM

An object list! Go to create new variable and select object then click list and just put them all into a list. Then make an infinite loop that repeats infinite times saying "For all objects in list" if item_from_allObjects is behind camera, item_from_allObjects isShowing == false, else item_from_allObjects isShowing == true.

zonedabone 02-28-2010 12:21 PM

That isn't exactly on topic, but I'll try working on it, too! It'd help to lower the strain on alice's texture drawing!

arty-fishL 02-28-2010 03:27 PM

This is very good
 
This is very good.

It runs very smoothly.

Ive only had one problem once, where it suddenly jumped through the wall, but as you say, more cylinders to block up the gap.

I will probably use this in one of my worlds and credit you.

It works with cylinders, but how are you going to make it work with objects that dont have a constant radius all the way round.
If you used the same engine then it would move around a cube (or any other shape) in a circle, which would look wierd, wouldn't matter though, the great collision is what makes it brilliant.

Good work, 6 star quality.

jediaction 02-28-2010 05:02 PM

Where is for all objects in list

Niteshifter 02-28-2010 05:10 PM

[QUOTE=jediaction;17766]Where is for all objects in list[/QUOTE]

At the bottom beside the while loop.

jediaction 02-28-2010 05:32 PM

How do i put it in?

jediaction 02-28-2010 05:39 PM

I need another way to increase frame rate. What are others, cant think of one

Niteshifter 02-28-2010 07:49 PM

You need to create a list, whether it be in an object or the world and when you drop the "For all in order/together", you would choose the list that you created.

As for the frame rate, I don't think that you can adjust this at the moment, but if you just want to speed the world up, you would set the world's speed multiplier (under seldom used properties inside world) to a higher number.

Dameria 02-28-2010 07:59 PM

Yeah, he was talking about the frame rate, not the speed of the world. The only way to decrease the frame rate is to use less objects and avoid using infinite loops (or while events because those are the same thing).

zonedabone 02-28-2010 08:18 PM

If you have an empty while loop that you're using to wait for something, simply add a wait method in there. Put something like 1/4 second in there, and then it will only be evaluated every 1/4 second. This is great for things that don't exactly need to be rapid, like in my collision program.

zonedabone 02-28-2010 08:28 PM

About irregular objects, any object can be made from multiple cylinders. Make several cylinders, and move them to be around the border. Hope this helps!:D

King Gamer(gorit) 02-28-2010 10:04 PM

That...
 
That would require unecisary objects, while the time to add in iregular objects would not take alot of coding, I will upgrade my engine tonight for it.

jediaction 03-01-2010 08:20 AM

[QUOTE=Dameria;17778]Yeah, he was talking about the frame rate, not the speed of the world. The only way to decrease the frame rate is to use less objects and avoid using infinite loops (or while events because those are the same thing).[/QUOTE]


Oh Darn i have over 1000 loops

[QUOTE=Niteshifter;17776]You need to create a list, whether it be in an object or the world and when you drop the "For all in order/together", you would choose the list that you created.

As for the frame rate, I don't think that you can adjust this at the moment, but if you just want to speed the world up, you would set the world's speed multiplier (under seldom used properties inside world) to a higher number.[/QUOTE]


Ive been using Alice for 3 years. I know that

[QUOTE=Niteshifter;17776]You need to create a list, whether it be in an object or the world and when you drop the "For all in order/together", you would choose the list that you created.

As for the frame rate, I don't think that you can adjust this at the moment, but if you just want to speed the world up, you would set the world's speed multiplier (under seldom used properties inside world) to a higher number.[/QUOTE]


There is not "if behind camera" option. Ive took so much time looking

arty-fishL 03-01-2010 12:39 PM

1 Attachment(s)
[QUOTE=jediaction;17799]There is not "if behind camera" option. Ive took so much time looking[/QUOTE]

U can do this, but it only seems to work for me with a dummy.
[LIST=1][*]drop a [B]dummy at the camera[/B][*]Set its [B]vehicle to the camera[/B][*]Drop an [B]'if/else'[/B] tile into the method[*]Then you go into the [B]functions tab[/B] for the [I][B][COLOR="Red"]object[/COLOR][/B][/I] you want to check for behind the camera[*]Scroll down to the [B]spatial relation[/B] subheading[*]grab the [B]'[I][COLOR="Red"]object[/COLOR][/I] is behind'[/B] into the [B]if/else[/B] bit[*]then set it to if [B]'[I][COLOR="Red"]object[/COLOR][/I] is behind [I]dummy[/I]'[/B][*]Make it do whatever you want (eg. disappear) when it is behind the dummy[*]Set it to loop[*]Then it will do whatever you set (eg. disappear) when it is behind the camera[/LIST]Obviously you can do this for any [COLOR="Red"][I][B]object[/B][/I][/COLOR] or multiple objects, or an object list

Here is an example, the sky goes red if the joey is behind and green if it is in front.
Move the camera with the mouse:

Dameria 03-01-2010 02:00 PM

Jediaction, I have already created a world for you showing how you check if an object is behind the camera, it is with the fish? Or did I not publish that world?

jediaction 03-01-2010 02:13 PM

[QUOTE=arty-fishL;17810]
Here is an example, the sky goes red if the joey is behind and green if it is in front.
Move the camera with the mouse:[/QUOTE]

Thanks but unfortunatly...every time i try adding one of these things the game crashes and i cant save so i cant do this. Ill try and figure out buy not now sorry and thanks for your time

zonedabone 03-01-2010 03:38 PM

Again about the irregular objects! Programing a square to collide is on the list of todos! But anything more complex just can't be done.

Dameria 03-01-2010 03:56 PM

Yes but you can make bigger objects act as a square by using spacial distance. I have tried to do this with my own collision detection, but it did not work as I wanted it to because of some weird way Alice sets up objects spacial properties.

zonedabone 03-01-2010 04:16 PM

Exactly. Round objects are the easiest to collide with each other. Easier code is faster code, and faster code is smoother code. That's why I chose this method.

nsprangers 03-05-2010 05:02 PM

Congrats and nice job making this.

It may be faster, easier, and smoother, but it doesn't actually solve the problem of detecting if any two objects have collided. Sure, you could make a wall of invisible cylinders along your flat wall, but whatever object you're moving would bounce along the wall. I've only had Alice downloaded for a couple days, but it seems you can only interact with distances between objects, not surfaces. So who knows if it can actually be done.

In the main collision detection block, you have an expression that says

[CODE]if ((cylinder distance to item_from_close objects) <=
((item_from_close objects's width / 2) +
(item_from_close objects's width / 2)
)
)[/CODE]

Why are you dividing the width twice then adding it together?

In your maintenance area, you add objects that are within 5 meters to the wold.Close objects list, and then below you remove anything that is more than 2 meters away. The second check, for more than 2 meters away, is only done every 1/4 second, but isn't the 5 meter check done only once since it's not part of any loop? If the 5 meter check is meant to initialize the world.Close objects list, it should probably be up at the top, outside the "do together" block.

jediaction 03-05-2010 07:30 PM

Zonabone, how is the online thigy coming. DO you have moving objects working. If not, im gonna try.

I mean like an object movign and showing up on two different running alices


All times are GMT -5. The time now is 07:09 PM.

Copyright ©2020, Carnegie Mellon University
Alice 2.x 1999-2012, Alice 3.x 2008-2012, Carnegie Mellon University. All rights reserved.