Any way to simulate scroll-to "shake"?

Get help using Construct 2

Post » Sun Feb 19, 2012 12:10 am

Any way to do this? I am doing my scrolling manually, and I miss this cool feature.
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Sun Feb 19, 2012 2:35 am

[Quote]+Always
-Set Scrollx to Player.x+Player.shake
-Set Scrolly to Player.y+Player.shake

+Player.shaketime>0
-Subtract 60*dt from Player.shaketime
-Set Player.shake to -10+random(20)

+Something happens
-Set Player.shaketime to 10 or something[/Quote]

Could use some tweaking to have the shake get weaker over time or be more consistent, but this should do!Tokinsom2012-02-19 02:37:37
Image
B
225
S
27
G
13
Posts: 1,774
Reputation: 18,024

Post » Mon Feb 20, 2012 12:43 pm

@Tokinsom, that has a problem... you can end off getting way off where the scroll is supposed to be, as the next value is generated from the adjusted value...
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Mon Feb 20, 2012 12:46 pm

+Player.shaketime <= 0
+Trigger once
-Set Player.shake to 0

You just have to get rid of the offset that Player.shake causes when the shake ends.Tokinsom2012-02-20 12:47:03
Image
B
225
S
27
G
13
Posts: 1,774
Reputation: 18,024

Post » Mon Feb 20, 2012 12:47 pm

Yeah, but if I want the shake to go for an extended period of time...
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Mon Feb 20, 2012 12:50 pm

What does that have to do with it? During the shake the scroll offset can only go from -10 to 10, and will stay anywhere in-between until shaketime hits 0. When that happens everything should be reset, setting the scroll position back to the player.
Image
B
225
S
27
G
13
Posts: 1,774
Reputation: 18,024

Post » Mon Feb 20, 2012 12:52 pm

if you do a
Code: Select all
set scroll to lerp(scroll,player,dt)


just use a variable as intermediate.
Code: Select all
set scrollVar to lerp(scrollVar,player,dt)
set scroll to scrollVar


Then you can easily add any noise you want on that
Code: Select all
set scrollVar to lerp(scrollVar,player,dt)
set scroll to scrollVar + random(-20,20)


(note: I didn't split things into X and Y... I'll let you do that :D)
Last edited by Yann on Sun Sep 14, 2014 12:05 pm, edited 1 time in total.
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Tue Jun 26, 2012 5:40 pm

@Yann @sqiddster
Can someone explain how this works please in a bit more detail.

This is my Camera settings to shake.

Every Tick > Sroll to position > X: PlayerBox.X
                        Y: lerp(PlayerBox.Y - WindowHeight /6.0, ScrollY, 0.5)
Layout size: 1.5


or up a .capx that would be sweet.Erndog2k2012-06-26 17:57:07
B
27
S
11
G
1
Posts: 246
Reputation: 5,048

Post » Tue Jun 26, 2012 6:33 pm

OK I figured it out

Global Variable: ShakeVar: 0


Shake by N7Effect, on Flickr

Ex: every 0.001/(Everytick) seconds: Animation playing "Shoot"

@Kyatric
Frequently asked Section Erndog2k2012-06-26 19:15:05
B
27
S
11
G
1
Posts: 246
Reputation: 5,048

Post » Tue Jun 26, 2012 7:41 pm

o.o people use flickr for construct2 0.0 keep going people nice idea :P
B
45
S
15
G
6
Posts: 795
Reputation: 11,935

Next

Return to How do I....?

Who is online

Users browsing this forum: austinblackbelt and 34 guests