PDA

View Full Version : Golf course with perlinNoise



harm-less
February 27th, 2009, 07:51 AM
Hello all,

I'm going to try to make a golf game, but I've a issue I can't solve myself.
As you know a golf course has a putter part where you need to put the in the hole to "win" the course. I only want to make this part. The scene is a top-view of the course, so you are looking down on the player.

My problem is the following, if you hit the ball it goes to a direction and its rolling over the course. But the grass field has variable heights, so if it hits a little bump is should slow down more because the ball is also going upwards to the top of the bump.
So you have to look good before you hit the ball, because perhaps you need to slightly turn to the left or right to get the ball in the hole properly.
Crappy description, but if you played Golf on the Wii I think you know what I mean. I found a video to show you what I mean, look at the 19sec (Runde 3). He turns to the left, else the ball didn't made the hole. http://www.youtube.com/watch?v=_mJdA3OeXuc

I did a little research and I think the best solution is perlinNoise. I found a script what partly has the features it requires:
http://blog.soulwire.co.uk/flash/actionscript-3/perlin-noise-flow-field/
See how the arrows go slower and faster depenting of the brightness of the rendered perlinNoise (that for downhill and uphill). It also looks turns depending on the perlinNoise.

I need a little push in the back to get started on this issue, I think making the rest of the game will not be hard.

Thanks in advance,
Harm

Avdi
February 27th, 2009, 11:17 AM
I dont see a video in your post, do you want the ball to just slow down over the bump or go around it too?

harm-less
February 27th, 2009, 09:29 PM
I dont see a video in your post, do you want the ball to just slow down over the bump or go around it too?

Now there is a link, thanks.

Ehm, imagine rolling a ball on almost flat field, the ball won't go straight because the surface is not even. It also decreases speed if it rolls up a hill, and down a hill it speeds up.

I need to recreate those physics.

scottc
February 28th, 2009, 06:28 AM
If your planning on using BitmapData and perlinNoise...

You'll have to get more then 1 pixel around the ball, then the link you posted.

For example, you could figure out the slope by getting the surounding 8 pixels and adding/subract the values to a point.



//slope direction variable
var slope:Point = new Point(0,0);

//modify the slope variable by the pixel values surrounding the ball..
//sample the pixels...

//topleft pixel
slope.x -= arrayOfPixelValues[0][0];
slope.y -= arrayOfPixelValues[0][0];

//top pixel
slope.y -= arrayOfPixelValues[1][0];

//top right
slope.x += arrayOfPixelValues[2][0];
slope.y -= arrayOfPixelValues[2][0];

//left pixel
slope.x -= arrayOfPixelValues[0][1];

//right pixel
slope.x += arrayOfPixelValues[2][1];

//bottom left pixel
slope.x -= arrayOfPixelValues[0][2];
slope.y += arrayOfPixelValues[0][2];

//bottom pixel
slope.y += arrayOfPixelValues[1][2];

//bottom right
slope.x += arrayOfPixelValues[2][2];
slope.y += arrayOfPixelValues[2][2];

//update the ball's speed variable, based on the slope.
ball.xVelocity += slope.x * 0.02; //2% of the slope value, so it doesn't go flying.
ball.yVelocity += slope.y * 0.02; //the 2% could be called gravity or whatever.

harm-less
March 3rd, 2009, 07:16 PM
If your planning on using BitmapData and perlinNoise...

You'll have to get more then 1 pixel around the ball, then the link you posted.

For example, you could figure out the slope by getting the surounding 8 pixels and adding/subract the values to a point.



Thanks man, that tip solved my problem. I even have speed loss when going uphill and faster when downhill. It took some time to figure it out, but I attached the result, :sen:check it out (http://harm-less.nl/golf.swf):sen:. Click behind the ball to give it speed again.

scottc
March 4th, 2009, 06:46 AM
Is it just me or is it unnatural how the ball moves away from the darker area's and towards the lighter area's? seeing that hills tend to get more sunlight then valleys. (might want to reverse the number by * -1)

Anyway i like this golf demo, its kinda cool... :D

Btw you could sample a larger area if you needed it to be more accurate..

Edit:
Is it just me or does the ball change size(distance) depending on the height of the terrain? :)