Math and physics

0 favourites
  • 3 posts
From the Asset Store
Simple yet very life-like rag doll made with Physics!
  • Hey Everyone,

    I have been doing a lot of work to understand how physics works with construct. Basically trying to figure out all the things that the manual doesn't tell you. Things like this:

    Velocity = Impulse/Mass * 2500

    Velocity = Force/Mass * 2500 (time)

    AngularVelocity = Torque/Mass * 648.78892733564 (time)

    Change in velocity = -Current Velocity * Linear Damping Coefficient (time)

    ...and other stuff, such as the difference between "set velocity" and using forces or impulses. There is also some order and logic peculiarities due to the Construct 2 update cycle.

    I wrote more about it here ->

    https://www.scirra.com/tutorials/1135/physics-the-rest-of-the-manual

  • Thanks Ruskul that was pretty helpful and needy one! I always use to get C at school, So really appreciate your help.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Short version:

    1.The 2500 is from the conversion factor (50) from box2d units to pixels.

    2. Your equation to calculate won't work for all shapes. Instead of just mass you need to calculate the Moment of Inertia for that particular object. After that the only magic number is 0.02 or (1/50) which is the conversion factor from pixels to box2d units.

    3. [quote:2iwgq6s7]AngularVelocity = Velocity / Diameter (pi)

    should be:

    AngularVelocity = Velocity * 180 / (radius * pi)

    Long Version:

    Box2d internally uses it's own distance unit (m) which is 0.02 pixels.

    The conversion is:

    1 [pixel] = 0.02 [m]

    or

    50 [pixel] = 1 [m]

    The set Velocity action and getVelocity expression already do the conversion without help, but the conversion isn't considered with Force or Impulse.

    Before I go any further I'd like to suggest that the mass expression is returning a bad value. The formula for mass with units is:

    Mass [d * m^2] = density [d] * area [m^2][/code:2iwgq6s7]
    Where [d*m^2] is the same as [kg]
    
    So for a 32x32 pixel square with density 1 the mass should be:
    [code:2iwgq6s7]area [m^2]= (height [pixel] * 0.02 [m/pixel]) * (width [pixel] * 0.02 [m /pixel]) = (32 * 0.02) * (32 * 0.02) [m^2] = 0.4096 [m^2]
    mass [d * m^2] = density [d] * area [m^2] = 0.4096 [d * m^2][/code:2iwgq6s7]
    But the mass expression returns 20.48 or 50 times 0.4096 which is incorrect since that makes the units [d*pixel*m].
    
    This is only important because if it were correct you'd only have to multipy by 50 instead of 50*50 or 2500 with the Force and Impulse equations.
    
    Torque is a bit trickier.  The equation for Torque is:
    [code:2iwgq6s7]Torque [kg*m^2*deg/s^2] = inertia [kg*m^2] * ang_accel [deg/s^2][/code:2iwgq6s7]
    
    [url=http://en.wikipedia.org/wiki/List_of_moments_of_inertia]Inertia is calculated differently for different shapes[/url].  For a square the equation is:
    [code:2iwgq6s7]Inertia = mass * (width^2 + height^2)/12[/code:2iwgq6s7]
    For mass we'll use 0.4096 and we'll need to covert height and width from [pixel] to [m] and we get:
    Inertia = 0.4096 * ((32*0.02)^2 + (32*0.02)^2)/12 =~ 0.02796...
    
    I then ran a test to apply a torque of 1 for 60 ticks. At the end the angular velocity was approximately 35.76. From that the acceleration could be calculated with acceleration=(final_speed-initial_speed)/time which ended up being 35.76.
    
    The numbers agreed with the equation when it was plugged in:
    torque = inertia * ang_accel
    1 ?= 0.02796 * 35.76 
    1 ~= 0.9998
    
    This link may also be useful as it predicts motion using equations much like yours.
    
    -cheers
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)