none
LD Physics question. (Again) RRS feed

  • Question

  • Hi all! I've been messing around with the 'ol' extension again and I've encountered a some strange behavior. on this game here: VCL709

    hold down the Up arrow key until the position of about 2000. for some reason it just freezes up right then. (Please tell me if you need a better explanation)

    Thanks!


    It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11

    Wednesday, September 11, 2013 11:17 PM
    Answerer

Answers

  • Hi, nice problem - glad some-one is having a go with the physics engine.

    The issue is the AABB (Axis aligned bounding box) set for the physics engine - the maximum region that it will calculate stuff.  This is not boundaries, they are just walls.

    The AABB is defaulted to -100,200,-100,200 (L,R,B,T).  These are in physics engine units which translate to (-1000,2000,-1000,2000) pixels.  I initially did this without reckoning on scroll bars coming later.

    I did add a method to change this though, SetAABB (the size of the physics world in physics engine units).  It needs a call to Reset to do it and probably should be the first LDPhysics command.

    I also set LDScrollBars.Rasterize = "False" to allow very large scroll region where background shapes are not rasterised to a bitmap (use less than 100 Drawables (shapes OK) in this case).

    Here is you code modified, import VCL709-0

    EDITS

    See also Example16.sb (in extension download and in pdf guide)  that does scrolling before the LDScrollBars were added - may be less jumpy.

    Normally I would put a boundary box somewhere inside or at least at the limits of the AABB so that if anything does get that far it will bounce back and not just get stuck outside its universe. 
    Thursday, September 12, 2013 6:22 PM
    Moderator

All replies

  • Hi, nice problem - glad some-one is having a go with the physics engine.

    The issue is the AABB (Axis aligned bounding box) set for the physics engine - the maximum region that it will calculate stuff.  This is not boundaries, they are just walls.

    The AABB is defaulted to -100,200,-100,200 (L,R,B,T).  These are in physics engine units which translate to (-1000,2000,-1000,2000) pixels.  I initially did this without reckoning on scroll bars coming later.

    I did add a method to change this though, SetAABB (the size of the physics world in physics engine units).  It needs a call to Reset to do it and probably should be the first LDPhysics command.

    I also set LDScrollBars.Rasterize = "False" to allow very large scroll region where background shapes are not rasterised to a bitmap (use less than 100 Drawables (shapes OK) in this case).

    Here is you code modified, import VCL709-0

    EDITS

    See also Example16.sb (in extension download and in pdf guide)  that does scrolling before the LDScrollBars were added - may be less jumpy.

    Normally I would put a boundary box somewhere inside or at least at the limits of the AABB so that if anything does get that far it will bounce back and not just get stuck outside its universe. 
    Thursday, September 12, 2013 6:22 PM
    Moderator
  • Thank you so much!!! One more question. How would I set a max speed for an object? I'm using "SetTorqe" and it just keeps spinning faster and faster. Thanks!

    It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11

    Friday, September 13, 2013 2:33 PM
    Answerer
  • The physics engine works by applying forces, not velocities or positions (these are calculated as a result of the applied forces).

    A force gives rise to an acceleration F = M.Acc

    A Torque is just a rotational force which gives rise to angular acceleration using inertial moment (basically mass).

    So we can apply an acceleration or brake (like in a car - there is no velocity or position control).

    We can check the current velocity and control the acceleration or torque accordingly, eg if velocity is greater than x, then don't apply more torque, regardless what the user does.

    If we are in a car and going at top speed and press full down on the gas we don't accelerate.

    Friday, September 13, 2013 2:40 PM
    Moderator
  • Genius! Pure Genius!!! I should of thought of that though :roll:

    It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11

    Friday, September 13, 2013 2:50 PM
    Answerer
  • In reality there is a resistance force opposing the force that drives a vehicle.  This is friction of the tires or air resistance etc.  It is usually proportional to velocity.  So the faster something goes (and the heavier it is) the more force (power) required to counteract this resistance and accelerate the vehicle.  A fast car needs lots of power, but at increasing speeds (air resistance drag becomes a bigger and bigger factor).

    If you look at the pool example you see I use LDPhysics.SetDamping - this is a velocity dependent force opposing the motion - just like air resistance or friction for an object not seeing friction by contact with a surface.  If the object is in constant contact with a surface, then friction for the floor (and wheels) will have a similar effect - try increasing the ground friction for example.


    Friday, September 13, 2013 6:35 PM
    Moderator
  • How would I change the collision on a image? Like adding this jump:

    How would I make the collision image have that circular pattern?


    It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11

    Thursday, September 19, 2013 12:02 AM
    Answerer
  • Maybe you can split Your vector into one vertical and one horizontal vector.

    Or convert an eg. horizontal/vertical vector to a normal (to the surface) vector, if You have the gradiant (? in engl.) dy/dx of the curve in that point.

     en.wikipedia.org/wiki/Parallelogram_of_force


    Thursday, September 19, 2013 1:43 AM
    Answerer
  • This is a physics extension question. not a physics formula. :D


    It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11

    Thursday, September 19, 2013 2:58 AM
    Answerer
  • As Pappa Lapub suggests you will have to break the required shape up into sub-shapes.  These sub shapes can then be joined (GroupShapes - See Example12) if they are mobile to move as one or just placed separately as static shapes like your ramp.

    You can use triangles or polygons, but polygons must be convex (your ramp is concave so would need several shapes).

    To use images is harder, they are rectangles and can be loaded in Small Basic to behave like rectangles or circles only.

    You could add the image as an inactive shape (not attached to the physics engine at all - or even draw it to the background) and then add transparent (physics engine active) shapes that have the right geometry for the boundary of your ramp.

    Thursday, September 19, 2013 9:20 AM
    Moderator
  • I got it figured out!!! Try this:

    ZLH548


    It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11

    Thursday, September 19, 2013 4:08 PM
    Answerer
  • This looks good, but it is concave and Box2D says it doesn't handle concave polygons.

    http://vvvv.org/forum/polygon-box2d-and-convex-shapes

    It is concave is any internal angle is > 180 deg.

    Thursday, September 19, 2013 5:15 PM
    Moderator
  • Never mind. It gave me this error:

    It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11

    Thursday, September 19, 2013 5:53 PM
    Answerer
  • Also I think Box2D limits polygons to 8 vertices (by default) - probably for good performance or other reasons.

    Nice looking graphics by the way.

    Thursday, September 19, 2013 6:02 PM
    Moderator
  • I got it all working!!


    It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11

    Friday, September 20, 2013 6:29 PM
    Answerer
  • I look forward to seeing it
    Friday, September 20, 2013 6:33 PM
    Moderator