• Login
sketchucation logo sketchucation
  • Login
🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

MsPhysics Script

Scheduled Pinned Locked Moved Newbie Forum
sketchup
2 Posts 2 Posters 2.0k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    markorvll
    last edited by 15 Jan 2022, 23:31

    Hello, I was wondering why I always get an error message when using the script for MsPhysics. Here's the script

    Triggered when simulation starts

    onStart {

    Have the desired velocity as 5 m/s

    @des_vel = 5
    }

    Triggered every time the world updates

    onUpdate {

    Compute the force to apply

    timestep = simulation.update_timestep # (in seconds)
    force = this.mass / timestep # (in Newtons)

    Get current velocity

    cur_vel = this.get_velocity

    leftx() returns a value ranging from -1.0 to 1.0, depending on the state

    of A and D keys or the horizontal position of the left joystick.

    fx = (leftx() * @des_vel - cur_vel.x) * force

    lefty() returns a value ranging from -1.0 to 1.0, depending on the state

    of W and S keys or the vertical position of the left joystick.

    fy = (lefty() * @des_vel - cur_vel.y) * force

    Apply force on this body.

    this.add_force(fx, fy, 0)
    }

    Not sure what I'm doing wrong.

    Thanks

    1 Reply Last reply Reply Quote 0
    • F Offline
      faust07
      last edited by 17 Jan 2022, 13:59

      It works for me.
      See attached model.


      Model SketchUp 2017 Make

      1 Reply Last reply Reply Quote 0
      • 1 / 1
      1 / 1
      • First post
        1/2
        Last post
      Buy SketchPlus
      Buy SUbD
      Buy WrapR
      Buy eBook
      Buy Modelur
      Buy Vertex Tools
      Buy SketchCuisine
      Buy FormFonts

      Advertisement