none
LDPhysics.AttachShapesWithJoint Parameters RRS feed

  • Question

  • Hi.

    I'm a bit stuck on how to use parameters in LDPhysics.AttachShapesWithJoint().

    I've tried multiple ways to add the parameters but it doesn't seem to change. I've copied the code below.

    LDPhysics.AttachShapesWithJoint(ball, ball, "Mouse", "False", "Mouse=1000,0.7")

    The code works without parameters but the shape moves too quickly with the mouse. Any help would be greatly appreciated.

    Thanks.

     ~Matt

    Thursday, August 22, 2019 4:11 PM

Answers

  • I reduced Litdev's extension example JOINTS.SB to the mouse. It works well and has a surprising rotation effect.

    gw = 600
    gh = 600
    GraphicsWindow.Width = gw
    GraphicsWindow.Height = gh
    GraphicsWindow.Title = "Joint - Mouse"
    LDPhysics.Reset()
    MakeMouse()
    
    While("True")
      start = Clock.ElapsedMilliseconds
      LDPhysics.DoTimestep()
      delay = 1000*LDPhysics.TimeStep - (Clock.ElapsedMilliseconds-start)
      If (delay > 0) Then
        Program.Delay(delay)
      EndIf
    EndWhile
    
    Sub MakeMouse
      mouse1 = Shapes.AddEllipse(30,60)
      Shapes.Move(mouse1,Gw/2-10,gh/2-10)
      LDPhysics.AddMovingShape(mouse1,0.5,0.5,1)
      LDPhysics.AttachShapesWithJoint(mouse1,mouse1,"Mouse","False","10000")
    EndSub

    • Marked as answer by MattSpeedberg Thursday, August 22, 2019 6:23 PM
    Thursday, August 22, 2019 5:38 PM
  • To use more than 1 parameter they should be an array,, below using array as string syntax it could be:

    LDPhysics.AttachShapesWithJoint(mouse1,mouse1,"Mouse","False","1=100000;2=2.7;")

    More damping than default and more acceleration to compensate a bit.


    Thursday, August 22, 2019 6:04 PM
    Moderator

All replies

  • I reduced Litdev's extension example JOINTS.SB to the mouse. It works well and has a surprising rotation effect.

    gw = 600
    gh = 600
    GraphicsWindow.Width = gw
    GraphicsWindow.Height = gh
    GraphicsWindow.Title = "Joint - Mouse"
    LDPhysics.Reset()
    MakeMouse()
    
    While("True")
      start = Clock.ElapsedMilliseconds
      LDPhysics.DoTimestep()
      delay = 1000*LDPhysics.TimeStep - (Clock.ElapsedMilliseconds-start)
      If (delay > 0) Then
        Program.Delay(delay)
      EndIf
    EndWhile
    
    Sub MakeMouse
      mouse1 = Shapes.AddEllipse(30,60)
      Shapes.Move(mouse1,Gw/2-10,gh/2-10)
      LDPhysics.AddMovingShape(mouse1,0.5,0.5,1)
      LDPhysics.AttachShapesWithJoint(mouse1,mouse1,"Mouse","False","10000")
    EndSub

    • Marked as answer by MattSpeedberg Thursday, August 22, 2019 6:23 PM
    Thursday, August 22, 2019 5:38 PM
  • To use more than 1 parameter they should be an array,, below using array as string syntax it could be:

    LDPhysics.AttachShapesWithJoint(mouse1,mouse1,"Mouse","False","1=100000;2=2.7;")

    More damping than default and more acceleration to compensate a bit.


    Thursday, August 22, 2019 6:04 PM
    Moderator
  • Thank you both for your quick responses. I'll test this out tomorrow!
    Thursday, August 22, 2019 6:23 PM