We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Using noise() for collision detection
Page Index Toggle Pages: 1
Using noise() for collision detection (Read 1155 times)
Using noise() for collision detection
Sep 29th, 2009, 12:39pm
 
Hello guys!

I have read elsewhere on the forums that noise() can be used for collision detection, and after reading what that function does, I somewhat have an idea of how it can be used.

However, is it possible to still use noise() if I would like to check for collision of a travelling ball on a square? I can't seem to find a pattern between the values of noise() throughout a sketch. If the values are random, am I right to say that collisions can only be detected at a specific x and y-coordinate?

Thank you!
Re: Using noise() for collision detection
Reply #1 - Sep 29th, 2009, 2:06pm
 
Personally, I fail to see the connection between noise and collision detection. If you could enlighten us...
Re: Using noise() for collision detection
Reply #2 - Sep 29th, 2009, 2:43pm
 
me either but when i read it i thought, "ok, dont wanna look stupid again wait for PhiLho to answer first" Wink
Re: Using noise() for collision detection
Reply #3 - Sep 29th, 2009, 10:18pm
 
It's simple, really: for instance, while driving a car, you may hear screams, muffled thumps, or splintering/cracking noises.  These indicate collisions.

seriously, though, if you mean this post:
http://processing.org/discourse/yabb2/num_1253661731.html
the collision detection discussed isn't facilitated by the noise per se, that's just how the terrain is generated.  The collision detection amounts to "if the player's Z var is dropping under the height (Z) of the noise/terrain map point at that (X,Y) location, that's a collision."

Once you generate your heightmap, you can store it any way you like, though I don't see why checking Z value at the ball's (x,y) wouldn't work for you...

--Ben
Re: Using noise() for collision detection
Reply #4 - Sep 30th, 2009, 1:05am
 
Quote:
These indicate collisions.
Grin Smiley
Re: Using noise() for collision detection
Reply #5 - Sep 30th, 2009, 6:54am
 
Hi BenHem, yup that was the topic I was referring to  Cheesy

Well since each x and y-coordinate at any point on the sketch is assigned with a value via noise(), I thought that to check for collision, one simply needs to match that particular value with the noise values for a moving ball, i.e.

//x and y coordinates of ball;
float ball_x, ball_y;
//x and y coordinates of rect;
float rect_x, rect_y;

float noiseBall = noise(ball_x, ball_y);
float noiseSquare = noise(square_x, square_y);

if (noiseBall == noiseSquare)
println("collision!);

I guess I'll try to understand how noise() works further Tongue

Thank you!

Tim.
Re: Using noise() for collision detection
Reply #6 - Sep 30th, 2009, 8:44am
 
Aha, well thought! Thanks for sharing your intuition.

I just see two issues with your reasoning:
- It works only if the ball has a size of 1...
- You can have the same noise value in two different points.

You can use, for example, the noise value as an elevation. Your check will just verify the point and the ball are at the same level.
Re: Using noise() for collision detection
Reply #7 - Sep 30th, 2009, 8:58am
 
Hello PhiLho,

Thanks for the list! I think these are the reasons why the sketch isn't working as well as I hoped it would, and I would have taken a loooong time to figure out why if you haven't shared that. Tongue Thank you!

Tim.
Page Index Toggle Pages: 1