1
$\begingroup$

I'm trying to figure out what's in the title. I've gotten regular spring physics working and now I'm trying to do something similar with actual collisions (player character colliding with the ground in a game at the moment).

I have an RK4 integrator running in my update loop and I think the only thing I'm missing is the formula that I should use. I've been reading this and I think I need to use the following formula: F=nkd-bn(n.v) where n is the contact normal, k and b are the spring damping coefficients, d is the desired distance of seperation, and v is the relative velocity between the two points connected by the spring.

I need it split up in an x and y value so this is what I've made of it so far:

var n = [0, -1];  // collision normal
var k = 1, b = 1; // spring coefficients
var sceneStates = [[posX, posY], [velX, velY]]; // current position and velocity of colliding object
var force = [0, n[1]*k*sceneStates[0][1]-b*n[1]*(dot(n, sceneStates[1]))]; // [x,y]

I hope this is enough information to let you known where I'm stuck.

$\endgroup$
  • $\begingroup$ First remark: I think that the specific integration method (RK4) is irrelevant in the question. $\endgroup$ – b.Lorenz Dec 6 '18 at 20:31
  • 1
    $\begingroup$ Second: It might be better answered at other SE-s (like game dev or overflow)) $\endgroup$ – b.Lorenz Dec 6 '18 at 20:32
  • $\begingroup$ Third: you should try to use mathematical formulas, as the code snippet is of little help in the present form. And also you would be wise to specify the meaning of the vectors in your formula $\endgroup$ – b.Lorenz Dec 6 '18 at 20:34
  • $\begingroup$ I'll see if I can post this elsewhere. I posted something similar on overflow earlier and they said I should ask here. I mentioned RK4 to give a complete idea of what I'm working with. The code snippet is just what I have, I'm not sure how else I can explain what I have and what the context is (math/physics are obviously not my strong suit) $\endgroup$ – Dries Dec 6 '18 at 21:08
  • $\begingroup$ Well. First thing you should do is to explain more clearly what you are trying to do: are there actual springs simulated? Or you are only using them as a simple model for contact forces when two bodies touch? $\endgroup$ – b.Lorenz Dec 6 '18 at 21:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.