i was wondering, how do u make objects detect collision in a script, and then add 1 to a box named counter? im terrible at java but im ok at html, so i know what abouts the script is doing, but not sure how to do it (if that makes any sense)
if anybody would be kind enough to write a script along theese lines and point out which each bit is doing, so i can get a slight understanding......
I didnt know theres another way to check colission exept hitTest or checking x and y positions. Unfortunately your file would not open on my computer.
Could you explain please. What is collideRect?
My example should run on 3D Flash Animator, version 4, release 4.
See http://www.3dfa.com for a free downloadable demo version.
3dfa has lots of nice, easy to use functionality for games, 3D stuff, and other Flash development. 'collideRect' is a command that tests if the bounding box of 1 element is in collision with that of another.
ie. 'element1.collideRect(element2)' would return true if the two elements were in collision.
hiya, thanks for your help. I did the collide.rect method of things, and changed the variables in the script (element1) to the names of my elements, but when i played the movie, i got this error message: collideRect() is not a method of Null on line 1 if (dark.collideRect(ball)) 1 error found. can anybody help? If poosible, could sombody dl the example i have, and "fiddle" with it to see where it went wrong. thanks
ps: theres also a readme to explain what im wanting
Originally posted by dontdothat hiya, thanks for your help. I did the collide.rect method of things, and changed the variables in the script (element1) to the names of my elements, but when i played the movie, i got this error message: collideRect() is not a method of Null on line 1 if (dark.collideRect(ball)) 1 error found. can anybody help? If poosible, could sombody dl the example i have, and "fiddle" with it to see where it went wrong. thanks
ps: theres also a readme to explain what im wanting
thanx
I didn't look at your code but you first have to get a 'handle' for your element or access it with the element function
assuming an element called dark and one called light (make sure that the "has properties for each is set"
Direct:
element ("dark").collideRect (element ("light"))
or in you start script assign handles to the elements
dark=element ("dark")
light.element ("light")
then in you action you can now use the 'handles'
dark.collideRect (light)
Oh and if you want to get really fancy you can detect collision on circular objects by calculating their distance and comparing it to their diameter using this function:
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
I attach a really simple example of how to start to add collisions to the movie:
You'll need to put something in to avoid getting multiple collisions on each drop, but this should give the general idea. I didn't put any fancy stuff in, coz that might be a bit confusing to start with.
M.
Incidentally - When you post movies on here, make sure to include any GIF's etc that are linked.
Last edited by ForumNewbie; 07-19-2003 at 05:26 AM.
is there anyway to add actions on collisions, like wen it hits it plays a sound?
and also can u write if else commands
so if it dusnt collide a point is deducted and a diff sound is played
forumnewbies example was spot on, so i decieded to use that, so i copied it exactly but in place of my own images, but id get it adding 6 to the counter (the time the object would take to pass over the counter) starngly enough this never happend on the orignial.... (?????)
anyways i set to work to solve this, and came up with this, yet again my attempt hit the ground like a cow from mars...
[list=1][*]Slow down how often you check for collision[*]Upon collision set a flag/variable to true and when no longer colliding set to false and only add once while true[*]When collision happens remove/move on of the objects so that they are no longer colliding[/list=1]
Each option has value and you have to decide in the context of your program which would make the most sense.
#2 would be my usual way.
PHP Code:
if (player.collideRect(moon)){//Did we collide
if (!player.hitcheck){//Make sure we weren't already colliding
player.hitcheck=true;//if not the set true we are
_root.counter++;//update counter
}
}else{
player.hitcheck=false
}
something like that or
in start script set
player.hitcheck=false;
then
PHP Code:
if (player.collideRect(moon) && player.hitcheck!=true){
//if colliding and not already colliding
root.counter++;
player.hitcheck=true;//set already colliding
}
if (!player.collideRect(moon) && player.hitcheck==true){
//if NOT colliding and hitcheck is true set to false.
playerhitcheck=false;
}
These are off the cuff and untested but should at least give you the idea.