Implementing springs!
We have now had some time to develop our project in Unity, and we decided that the first was to implement our own spring system between two objects. To do this used Hooke´s law that states that the force from a mekanical spring is proportional to the deviation from the equilibrium. Hooks law looks like this: F = k*x where k is a constant and x is the deviation from the equilibrium. We implemented Hooke´s law into a script in Unity connecting one GameObjects rigidbody to another GameObject. To start of with it looked something like this:
As you can se from the video above the current stage of the spring script doesn´t allow the GameObject that is attached to the spring to stop bouncing. To fix this problem we added dampening to the script which, regarding to the rigidbodys velocity and a dampening factor, made the GameObject evetually slow down.
As you can se from the video above the current stage of the spring script doesn´t allow the GameObject that is attached to the spring to stop bouncing. To fix this problem we added dampening to the script which, regarding to the rigidbodys velocity and a dampening factor, made the GameObject evetually slow down.
Hooke's law together with the dampening force looks like this: F = k*x - b*v where b is the dampening factor (set to 0.8 in the video above) and v is the velocity of the GameObject. Also, in the second video i alter the resting distance of the spring to demonstrate the dampening effect.
Kommentarer
Skicka en kommentar