I think the main problem here is that swapDepths just swaps the depths of elements, rather than taking into account which one was in front to start with.
So it looks to me as if the script is continually swapping them in both senses, and the end result is that they always stay where they are.
Attachment deleted because it was no help
I tried to do the same with pins in a 10 pin bowling game, but found the only way was to destroy the clone and recreate the clone each time there was a collision to be sure it was in the foreground.
If anyone has a better idea, I'd love to hear it.
ForumNewbie
Last edited by ForumNewbie; 11-16-2003 at 09:24 AM.
I'm ruipaiva
I have had problems in my pc and i was forced to do another registration here.
Yes, your solution probably can solve the problem.
I go to try change depths only when there is a collision.
Thanks a lot.
Rui
Just to let you know, and maybe save you some time, I tried to add collision detection to your animation, but it still didn't work quite right.
I think that's because you never know how many times the script will run during the collision. As a result, it may swap once, twice, (or more times) during the collision, and end up the wrong way round again.
You'll need to add something into the script that makes sure the swapping process only runs the script once per collision.
Also, I think you'll need to make sure the cloned elements are created in a particular sequence, so that the furthest back one is created first, and the closest to the front is created last. This makes sure they're in the right sequence before they start swapping.
I'm not 100% sure on that last point, but it certainly seemed to work best when I did that to it.
Hi ForumNewbie:
Yes, you have reason... That's true...
It's necessary swapDepth when collidge, stop script for these two objects, still work for anothers, check when first two objects end collition.
Probably with a flag or each one object, -1 in colliting, 0 end collition... Who check when end collition?...
Seems complicated, isn't it?...
So, i'm trying...
Thank you very much for colaboration.
PS - i have another problem is my mind, imagine a cube menu, each one face is a button, this cube move arround 3d axes like this script...
What do you think about?...
Rui Paiva
what you do is set a flag variable hascollided=false
then in your collision test
you do
PHP Code:
if (element1.collideRect (element2) && !hascollided){
hascollided=true;
//do your collision code here should only happen the first time
//they collide as we have set hascollided to true now
I decided the whole logic of the swapping wasn't going to work, so I tried another method. I created 2 arrays, to indicate which ball should have been at what depth based on it's scale parameter, and which it actually was at, based on it's starting depth.
Unfortunately, it seems to cause 3dfa a problem due to some extreme looping, but it works in the browser.
hi
i have been thinking about swapDepths because my solution, attached file on last message don't work quit well.
one option is clone 16 times, clones 8 till 15 are a copy of 0 to 7.
in case of clone 0 have z = 90 and is colliding with clone 5 with z = 40, then as this have a depth more elevated, we hide clone 0 and show clone 8, when collision end, we hide 8 and show again clone 0.
but this duplicate pc work, because is moving clones 0 - 7 and 8 - 15, at the same time.
another option is probably clone only when start collision and destroy it after end collission, in this case, the number of duplicated clones are small and of course then small will be the pc work.
i don't know, it's very complicated...
bibi
Rui Paiva
I assume when you said you had a problem with my method, it was because it doesn't work well in 3dfa. That's a 3dfa problem with loops, but the code does work. There may be a more efficient way to do it, which perhaps someone could help us with.
I think that getting the code in this example to run more efficiently might be more effective than the cloning method. Perhaps we can find out how to disable the 3dfa 'breaking out of loop, >100000 lines' feature which might sort out the problem in 3dfa.
Hi ForumNewbie:
Your demo work really nice.
You got the goal.
I presume then this demo work just with same code you attached.
I go try export it to html to check.
Really spectacular... Nice work.
Rui Paiva
i have a problem quite similar to this one.
i like to have a collision detection to make clones disappear, but of some reason this won't work. any idea, how i can solve this?
You could use my distance check for collision and that will always work for clones.
Or if they are circular use the Circle collision which uses the distance method
PHP Code:
*/
//*************************************
//simple distance test
//*************************************
function distance(element1,element2)
{
a=element1.x - element2.x;
b=element1.y - element2.y;
return sqrt (a*a+b*b);
}
function C_collide(element1,element2)
{
//get width of both elements
width1=(element1.getBounds().xMax-element1.getBounds().xMin)-6
width2=(element2.getBounds().xMax-element2.getBounds().xMin)-6
//get distance
a=element1.x - element2.x;
b=element1.y - element2.y;
dist= sqrt (a*a+b*b);
//account for different sizes
width=(width1/2)+(width2/2);
//check distance and size