Miscellaneous physics questions

I have two physics bodies which at some point collide. Is it possible to get their velocities before the collision was resolved?

you could save them at each draw… but you’ve already thought of this…

Yeah but thanks, I guess I could use masks so the bodies don’t react to the collision and then access their velocities in the collide(contact) function

Is there a way to use or replicate a mouse joint in box2d. This is a joint that pulls a body toward a certain point. Thanks for any answers.

Whoops double post of the same question

@Coder You could use “sensor” to ignore collisions but still get collision information. Here’s an example to show the velocities.


supportedOrientations(LANDSCAPE_ANY)

function setup()
    physics.continuous=true
    b=physics.body(CIRCLE,20)
    b.x=600
    b.y=200
    b.linearVelocity=vec2(-140,450)
    b.sensor=true
    
    b1=physics.body(CIRCLE,20)
    b1.x=100
    b1.y=100
    b1.linearVelocity=vec2(120,500)
    b1.sensor=true
end

function draw()
    background(40,40,50)
    fill(255)
    ellipse(b.x,b.y,40)
    ellipse(b1.x,b1.y,40)   
end

function collide(c)
    if c.state==BEGAN then
        print(b.linearVelocity)
        print(b1.linearVelocity)
    end
end

@Coder As for the joint, you might be able to use a “prismatic joint”. That keeps movement in a line between 2 points. You could set the velocity of one object towards the other to make it look like it’s being pulled.

EDIT: If you explain what you’re doing with the joint, maybe we could come up with something that will work.

@dave1707 for the mouse joint i could use the same method as in the physics example which uses body:applyForce(). As for my first question I would like collisions to be resolved only if the forces involved are low enough.