Gamestudio Links
Zorro Links
Newest Posts
MT5 bridge not working on MT5 v. 5 build 4160
by EternallyCurious. 04/25/24 20:49
Data from CSV not parsed correctly
by EternallyCurious. 04/25/24 10:20
Trading Journey
by howardR. 04/24/24 20:04
M1 Oversampling
by Petra. 04/24/24 10:34
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
0 registered members (), 715 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mega_Rod, EternallyCurious, howardR, 11honza11, ccorrea
19048 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
flying leaf ... #298140
11/12/09 13:22
11/12/09 13:22
Joined: Feb 2006
Posts: 1,011
Germany
pegamode Offline OP
Serious User
pegamode  Offline OP
Serious User

Joined: Feb 2006
Posts: 1,011
Germany
Hi,

I'd like to add some flying leaves to my outdoor level.

Has someone an idea how to do this best?

I have a script that calculates a random wind force and direction. Now I'd like to move the leaves with those forces.
If the wind is still the leaves should fall to the ground and start flying if the wind blows again. The leaves shouldn't be able to fly through models.

Do I have to use the physics engine or is there a better way that saves fps?

Regards,
Pegamode.

Re: flying leaf ... [Re: pegamode] #298603
11/16/09 11:10
11/16/09 11:10
Joined: Feb 2006
Posts: 1,011
Germany
pegamode Offline OP
Serious User
pegamode  Offline OP
Serious User

Joined: Feb 2006
Posts: 1,011
Germany
I have a code that randomly generates wind and stores it into a variable that holds the wind strength (w_speed_current) and a vector for the wind direction (d_direction_current).

Then I wrote this little test-script:

Code:
action leaf() {	
	my.flags |= FLAG2;
	var accUp = 0;	
	var accDown = -0.5;
	while(me) {					
		if (w_speed_current > 0.3) {
			accUp = w_speed_current * 2;
			my.roll += 2;
			my.tilt += 5;
		} else {
			if (w_speed_current > 0) {
				my.roll += 2;
				my.tilt += 5;
			} else {
				my.tilt = 90;
			}
			accUp = 0;			
		}
		vec_to_angle(my.pan, d_direction_current);				
		accDown = -0.5 - random(1);		
		c_move(me, vector((d_direction_current.x+random(2))*w_speed_current*0.5, (d_direction_current.y+random(2))*w_speed_current*0.5, accUp),vector(0,0,accDown), IGNORE_PASSABLE | IGNORE_PASSENTS | GLIDE);
		wait(1);
	}	
}



Has someone an idea or hints how to make it look a bit more realistic?

Regards,
Pegamode.

Re: flying leaf ... [Re: pegamode] #298643
11/16/09 17:18
11/16/09 17:18
Joined: Jun 2006
Posts: 2,640
Earth
Germanunkol Offline
Expert
Germanunkol  Offline
Expert

Joined: Jun 2006
Posts: 2,640
Earth
Leaves always turn a lot. Look for reference videos maybe?
I find this one's good, but it lacks the wind:
http://www.youtube.com/watch?v=-NYYWp7Pa7s

another one where they turn and twist a lot:
http://www.youtube.com/watch?v=DLr1oWjIC44

I think if wind blows, they often fly back up a little (while being blown away) before tilting to make a looping and then come down at a steeper angle.


~"I never let school interfere with my education"~
-Mark Twain
Re: flying leaf ... [Re: Germanunkol] #298714
11/17/09 07:47
11/17/09 07:47
Joined: Feb 2006
Posts: 1,011
Germany
pegamode Offline OP
Serious User
pegamode  Offline OP
Serious User

Joined: Feb 2006
Posts: 1,011
Germany
Thanks for the links ... I'll take a look at them.

Re: flying leaf ... [Re: pegamode] #298813
11/18/09 06:59
11/18/09 06:59
Joined: Jun 2004
Posts: 2,234
Wisconsin USA
FoxHound Offline
Expert
FoxHound  Offline
Expert

Joined: Jun 2004
Posts: 2,234
Wisconsin USA
Just have the leaves rotate and base how fast off of how fast the wind is. Without looking at your script to much it looks pretty good and you should be able to pull this off.


---------------------
There is no signature here.


QUIT LOOKING FOR ONE!
Re: flying leaf ... [Re: FoxHound] #298829
11/18/09 09:03
11/18/09 09:03
Joined: Feb 2006
Posts: 1,011
Germany
pegamode Offline OP
Serious User
pegamode  Offline OP
Serious User

Joined: Feb 2006
Posts: 1,011
Germany
I think there's one part I have to improve a lot ...

When the wind is still, but the leaf is in the air it has to fall down slowly from the sky ... but a leaf doesn't fall down in a straight line. I think I have to add some sinus / cosinus stuff ... hints are welcome :-)

Re: flying leaf ... [Re: pegamode] #298901
11/18/09 22:13
11/18/09 22:13
Joined: Jun 2004
Posts: 2,234
Wisconsin USA
FoxHound Offline
Expert
FoxHound  Offline
Expert

Joined: Jun 2004
Posts: 2,234
Wisconsin USA
way to complicated. When the wind stops, and wind doesn't really stop it slows own to a still, just have the leave lose it's Z and go toward the earth in the same direction it was going. throw in some random left and right and you should do fine.


---------------------
There is no signature here.


QUIT LOOKING FOR ONE!
Re: flying leaf ... [Re: FoxHound] #298976
11/19/09 21:41
11/19/09 21:41
Joined: Feb 2006
Posts: 1,011
Germany
pegamode Offline OP
Serious User
pegamode  Offline OP
Serious User

Joined: Feb 2006
Posts: 1,011
Germany
This code works quite good for me:

Code:
action leaf() {	
	my.flags |= FLAG2;
	my.push = -100;
	var accUp = 0;	
	var accDown = -0.5;
	var distDown = 0;
	trace_mode = IGNORE_ME + IGNORE_PASSABLE + IGNORE_PASSENTS;
	
	VECTOR vDirection;
	VECTOR vDistance;
	VECTOR vDifference;
	
	ANGLE targetPan;
	
	vec_set(vDirection, vector(0,0,0));
	vec_set(vDistance, vector(0,0,0));
	vec_set(vDifference, vector(0,0,0));
	
	while(me) {					
		
		vec_diff(vDifference, vDirection, d_direction_current);
		vec_accelerate(vDistance, vDirection, vDifference, 2.5);
		
		distDown = c_trace(my.x,vector(my.x,my.y,my.z-1000),trace_mode);									
		
		if (w_speed_current > 0) {
			if (w_speed_current > 0.5) {
				accUp = w_speed_current * 2 * time_step;				
				my.roll += 5 * time_step;
				my.tilt += 8 * time_step;				
			} else {							
				my.roll += w_speed_current * 10 * time_step;
				my.tilt += w_speed_current * 10 * time_step;							
				accUp = 0;			
			}	
		} else {
			if (my.tilt < 0) {
				if (0 - my.tilt - 5 > 5) {
					my.tilt += 5 * time_step;
				} else {
					my.tilt = 0;
				}
			} else {
				if (0 - my.tilt + 5 < 5) {
					my.tilt -= 5 * time_step;
				} else {
					my.tilt = 0;
				}
			}			
			if (my.roll < 90) {
				if (80 - my.roll - 5 > 5) {
					my.roll += 5 * time_step;
				} else {
					my.roll = 0;
				}
			} else {
				if (90 - my.roll + 5 < 5) {
					my.roll -= 5 * time_step;
				} else {
					my.roll = 0;
				}
			}
		}		
		
		vec_to_angle(targetPan, d_direction_current);				
		if (my.pan < targetPan.pan) {
			if (targetPan.pan - my.pan > 5) {
				my.pan += 5 * time_step;
			} else {
				my.pan = targetPan.pan;
			}
		} else {
			if (targetPan.pan - my.pan < 5) {
				my.pan -= 5 * time_step;
			} else {
				my.pan = targetPan.pan;
			}
		}
		accDown = accUp - 0.2 - random(0.5) * time_step;		
		if (distDown < 0.4) {
			accDown = 0;
		}		
		
		c_move(me, vDistance, vector(0,0,accDown), IGNORE_PASSABLE | IGNORE_PASSENTS | GLIDE);
		wait(1);
	}	
}



I'll refactor this later on.

Re: flying leaf ... [Re: pegamode] #299006
11/20/09 07:00
11/20/09 07:00
Joined: Oct 2004
Posts: 1,655
T
testDummy Offline
Serious User
testDummy  Offline
Serious User
T

Joined: Oct 2004
Posts: 1,655
Quoting pegamode.
Quote:
This code works quite good for me:

For how many leaves?

Re: flying leaf ... [Re: testDummy] #299012
11/20/09 08:05
11/20/09 08:05
Joined: Feb 2006
Posts: 1,011
Germany
pegamode Offline OP
Serious User
pegamode  Offline OP
Serious User

Joined: Feb 2006
Posts: 1,011
Germany
Currently I'm using it only for 3 leaves at a time, but I think you can use it for quite a lot of leaves as it doesn't cost that much.

The only slow function is the c_trace, but if it should be too slow for plenty of leaves you could take it out and do the ground detection slightly different.

If you use this code you will have to adjust the parameters to fit into you game as the code stands and falls with the values in w_speed_current.

Regards,
Pegamode.


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1