### Shared Mechanics

#### ceosol

• Posts: 2189
If you have some neat mechanics you want to share, feel free to post here. Please make sure to include the written code or blocks so people know what you are referring to.

SadiQ asked me if I could calculate spring mechanics without using physics blocks. Here is what I came up with:
u = current velocity
v = new velocity
s = stretch of the spring (distance from the center position)
t2 = the time squared, although I just put in my own value
200 is the center
300 is the y starting position of the actor

It is set up like that because I wanted to pull apart the equation to make sure it was written correctly.

The original equation is F = m * (v-u)/t^2 = k * s

*note - there is a linear dampening factor in there (the 0.99999).

<a href="http://static.stencyl.com/games/34042-0.swf" target="_blank" class="new_win">http://static.stencyl.com/games/34042-0.swf</a>

#### mdotedot

• Posts: 1331
Very Cool! You could upload to stencylforge?!?!

I've made a stencyl file with this. You can click on the actor to re-spring it.

https://dl.dropboxusercontent.com/u/107982821/stencyl/spring.stencyl

Hanging out in the Chat:  http://www.stencyl.com/chat/

Proud member of the League of Idiotic Stencylers! Doing things in Stencyl that probably shouldn't be done.

• Posts: 2547
To simulate elasticity effect I always use trig functions:

<a href="http://static.stencyl.com/games/34050-0.swf" target="_blank" class="new_win">http://static.stencyl.com/games/34050-0.swf</a>
I'm spanish, excuse me for my bad English.
I'm not a private teacher. Please, post your questions in the public forum.

• Posts: 1766
<a href="http://static.stencyl.com/games/34051-0.swf" target="_blank" class="new_win">http://static.stencyl.com/games/34051-0.swf</a>

I managed to hack something up using some simple particles and springs. I ended up using a different code:

Code: [Select]
`private function updateParticles(){ //fthis is used for the spring effect for (i in 0 ... particlesArray.length) { var particle = particlesArray[i]; var stiffness = 0.004; var dampness = 0.02; var dx = particle.x - particle.startx; var dy = particle.y - particle.starty; var accelx = ( -stiffness * dx) - (dampness * particle.vx); var accely = ( -stiffness * dy) - (dampness * particle.vy); particle.x += particle.vx; particle.y += particle.vy; particle.vx += accelx; particle.vy += accely; } //more stuff was below}`
Proud member of the League of Idiotic Stencylers! Doing things in Stencyl that probably shouldn't be done.

• Posts: 2547
To simulate rope swinging effect I use trig functions and curve drawing:

<a href="http://static.stencyl.com/games/34058-0.swf" target="_blank" class="new_win">http://static.stencyl.com/games/34058-0.swf</a>

« Last Edit: April 20, 2016, 11:50:54 pm by LIBERADO »
I'm spanish, excuse me for my bad English.
I'm not a private teacher. Please, post your questions in the public forum.

• Posts: 1766
Proud member of the League of Idiotic Stencylers! Doing things in Stencyl that probably shouldn't be done.

• Posts: 2547
I'm spanish, excuse me for my bad English.
I'm not a private teacher. Please, post your questions in the public forum.

• Posts: 1766
http://www.stencyl.com/game/play/33915 (10k ->pixel particles)
http://www.stencyl.com/game/play/33924 (1024 -> pixel particles)
http://www.stencyl.com/game/play/33944 (forgot how many ->image particles with some blur)
Proud member of the League of Idiotic Stencylers! Doing things in Stencyl that probably shouldn't be done.

• Posts: 2547
@SadiQ awesome! Do they work only in Flash?
I'm spanish, excuse me for my bad English.
I'm not a private teacher. Please, post your questions in the public forum.

#### colburt187

• Posts: 2197
You guys are so good its criminal, this is a really fun thread!

• Posts: 1766
@LIBERADO: I think it should work on all the targets, but I only tested them on flash and windows.
In windows I can get about 20 -25k particles before the framerate starts to drop, but I guess the numbers must be lower on mobile.
@colburt: Yeah mate, Liberado is a monsters when it comes to making cool stuff.  MdotEdot is highly skilled when it comes time to innovate (especially in the multiplayer aspect) and ceosol is a master of prototypes (his list of games is huge!).

The chat room gets filled with interesting stuff when we have some time to kill
Proud member of the League of Idiotic Stencylers! Doing things in Stencyl that probably shouldn't be done.

#### ceosol

• Posts: 2189
Here's a really quick daily reset. You can use it to reset scores or have a bonus item, RNG prize wheel, etc. The 86400000 is for one day. If you want it to be 2 days, multiply by 2. If you want one hour, divide by 24. The "set dailyscore to 0" part is what you would change if you wanted anything else to happen at the reset.

#### poehyrulian

• Posts: 78
Hi everyone this is a block setup for a boomerang effect. the charge effect is a little buggy cause sometimes the boomerang doesn't die when it reaches the player. I will make it better with more experience but this is the best I can do atm. the hold attack is to disable player movement while controlling the boomerang.

#### ceosol

• Posts: 2189
I was just playing around and I think you could use this to create a Fez type game in Stencyl. You would need 4 sides just have keep track of which side of the "cube" you were on.

FYI: it would need to be modified for large scale production to include values for telling each square where to go.

• Posts: 1008