# Sine Behaviour on Grass to Simulate Wind?

Get help using Construct 2

### » Sat Feb 28, 2015 3:44 pm

Posted a gif below to show you an example of what I'm hoping can be accomplished.

I know how to create the directional wind, where the angle of the sine is the same for each clump of grass. That's easy enough What I'd like to be able to do is calculate what the angle of each grass sprite should be for a radial burst of wind, based on where the burst of wind originates from relevant to the position of each grass sprite. So rather than all moving, say, 10 degrees to the right, some will move 10 degrees to the left, some 5 degrees one way, some 2 degrees, etc. Would that be possible?

B
15
S
8
G
7
Posts: 256
Reputation: 5,370

### » Sat Feb 28, 2015 4:41 pm

Use: angle(x1, y1, x2, y2) to get the angle between the 2 objects.

Then you can be even more fancy and use: distance(x1, y1, x2, y2) to calculate the distance between the objects, and depending on how far they are, you can make them wave less.

So you will need some form of collision detections first, then you can just loop through each grass sprite that is touched and use the above calculations.
Frosty Elk AB
www.frostyelk.se
Have no fear, We come in peace!
B
13
S
3
G
1
Posts: 106
Reputation: 1,169

### » Sat Feb 28, 2015 5:52 pm

If you're going to bend grass, maybe you can take a look to the skew/skend effect by Somebody : nearly-daily-effects-by-somebody-neat-things-big-gifs_t123401

B
12
S
7
G
7
Posts: 450
Reputation: 4,276

### » Sat Feb 28, 2015 10:32 pm

For like your picture you can use cos() to calculate the amount to rotate. Grass directly above and below won't rotate at all, and grass directly to the sides will rotate the most. 10 degrees in the following.

Set angle to 10*cos(angle(centerx,centery,grass.x,grass.y))
B
97
S
36
G
131
Posts: 5,519
Reputation: 83,476

### » Mon Apr 20, 2015 2:56 pm

R0J0hound wrote:For like your picture you can use cos() to calculate the amount to rotate. Grass directly above and below won't rotate at all, and grass directly to the sides will rotate the most. 10 degrees in the following.

Set angle to 10*cos(angle(centerx,centery,grass.x,grass.y))

Reviving and old post here, but this seems to be what I'm looking for, however I don't quite understand how to use that expression. When implementing it I get an error. What is centerx and centery?
B
10
S
3
Posts: 65
Reputation: 780

### » Mon Apr 20, 2015 5:42 pm

"centerx" and "centery" can be replaced with any x and y you want to use as a center.
B
97
S
36
G
131
Posts: 5,519
Reputation: 83,476

### » Tue Apr 21, 2015 12:47 pm

Sorry, I still don't get how to achieve the effect shown in the gif? (I'm new to Construct). I implemented the expression, but it doesn't do anything.

I have sprite called grass, I want moving like that, what do I write, and what's the condition (I'm assuming every tick)?
B
10
S
3
Posts: 65
Reputation: 780

### » Tue Apr 21, 2015 12:54 pm

Create an event

every tick - grass set angle = 10*cos(angle(mouse.x,mouse.y,grass.x,grass.y))

I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Thanks!
B
10
S
3
Posts: 65
Reputation: 780

### Who is online

Users browsing this forum: Google [Bot], mallorcaredes, x3fold and 9 guests