# How to make a spring with physics?

Get help using Construct 2

### » Thu Dec 05, 2013 6:34 pm

hello everybody i need your help i want to make a spring using physics i am not looking to fake it just a simple spring
any help or suggestion is more than welcome
B
7
S
2
Posts: 44
Reputation: 668

### » Thu Dec 05, 2013 8:39 pm

The simple formula for a spring force is F=kx, where k is the strength of the spring and x is the difference of length from a rest length.

Here is a capx of it in action.
https://dl.dropboxusercontent.com/u/5426011/examples20/spring_physics.capx

I also added damping which uses the formula F=-cv, where c is the damping strength and v is the object's velocity along the length of the spring. In the capx the formula looks a bit much because of a vector projection but it works.
B
95
S
34
G
128
Posts: 5,494
Reputation: 81,676

### » Fri Dec 06, 2013 11:47 am

@R0J0hound
first thanks you very much for your time to set up an example for me realy appreciate it
second i want to ask How could i limit the spring movement at certain angle example it move only in 45 degres
i just could not find the formula .
when i set the "spring_angle" to constant it became out of control.
tnindie2013-12-06 11:49:52
B
7
S
2
Posts: 44
Reputation: 668

### » Fri Dec 06, 2013 8:47 pm

Apply an additional force to move the object to a 45 degree direction:
ex:
Apply force -10*(spring_angle-45) at angle spring_angle+90

10 is the strength and 45 is the target angle in the range of (-180,180).

I suppose it could use a damping force as well...
B
95
S
34
G
128
Posts: 5,494
Reputation: 81,676

### » Sat Dec 07, 2013 4:33 pm

@R0J0hound
i want to thank you for your effort but i puling the triger on the idea .
its a work around the box2d prismatic joint which C2 does not support and cocoojs also.
thanks again for your time and help .
B
7
S
2
Posts: 44
Reputation: 668

### » Sat Dec 07, 2013 8:08 pm

Very informative all the same! Thanks
B
9
S
3
G
1
Posts: 112
Reputation: 1,827