- Home /
How Can I Implement Spring Force Physics to Simulate a Spring? (C#)
Hi, I'm working on a 2D top-down game and am trying to make something so that when the player collides with this spring objects "loose end" and based on a rigid body force it will be pushed back. I need to use F = - k x as a basis for my code. What I have set up so far is the spring object with a loose/fixed end:
I want to make a script using that formula of (F = - k x) that compresses the "loose end" towards the "fixed end" and based on a rigid body force pushes the player back. Trying to set-up spring force equation - distance traveled from the relaxed position, then use spring force to determine how much is force needed to compress spring and then when it will stop compressing and push the player back. Any help or examples would be amazing as I'm fairly new to coding with physics apart from built in options.
Your answer
Follow this Question
Related Questions
Configurable Joint chain with no spring/stretch? 2 Answers
Make Rigidbody not move away from Hinge Joint under force/ weight. 1 Answer
How to create a trampoline kind of object in unity? 1 Answer
When to apply delta time for framerate independence. 1 Answer
Object Oscillation like a spring 0 Answers