SketchyPhysicsWiki
Advertisement

Is a part of LazyScript Plugin


GetSpeed

Will calculate linear speed of the SP object the function is used in.

getSpeed(limit)

Limit - determines the upper limit of the output speed

Returns the speed of object in inches per second (inches is SketchUp's standard unit)

Example:

object_speed=getSpeed() #returns speed of the current object
object_speed=getSpeed(250) #max speed will be 250

EndSim

One call of this function will force the SkethyPhysics simulation to reset/end. Very usable for any Game Over screen.

endSim()


RestartSim

One call of this function will force the SketchyPhysics simulation to restart (it will end it and run again). Comes in handy for restarting a game level once you lose.

restartSim()


LoadNewFile

This function allows you to load a new SketchUp model, and run SP automatically after it loads.

IMPORTANT!

- make sure this functions runs only ONE time, should it be called more then once from your simulation it will crash Sketchup

- if the input file is not found/cannot be loaded it will only restart the current model

loadNewSim(new_file)

new_file - model file name(can also include a path), expected to find the file in the current folder

Example:

loadNewSim("Level2.skp") #will load a model named Level2.skp and run the simulation

if frame==1000 #to make sure the load function will only run on one frame
  loadNewSim("Level2.skp")
end


EditableControls

Allows easy control management/editing. No functions needed here, it will run automatically once included in the model.

This is how it works:

  1. The script will look for SketchyPhysics watermark text where it says "Requires SketchyPhysics3 RC1"
  2. It expects the controls to be defined in there, if no wattermark text is found it simply will not work
  3. Define the controls within tags <Controls> and <end>, everything outside that will be ignored
  4. You can then retrive the control values with getVar("Control name")
  5. Any changes to that text will then be used in the simulation, so anyone using your model can quickly change the control layout to his preference

Example watermark text:

Requires SketchyPhysics3 RC1
 

This is the control block:
<Controls>
k(A) + j(A)  ---------------- motor_power
e(LEFTX)   ------------------ steer
k(B) + k(SPACE) ------------- power2
k/C   j/X ------------------- power3
<end>

Now in the control block we got controls defined line by line

k(A) + j(A) --------------- motor_power

First part are the controls: k(A) + j(A)

  • k(A) does the exact same thing as key('A'), so k defines that its a keyboard button and A which one it is
  • j(A) works the same as joybutton('A'), so it is the same here j defines that it is a joypad button, and A which one
  • e(LEFTX) works the same as leftx, here we got e that defines it is an emulation, and LEFTX which one

(emulations: leftx, lefty, rightx, righty)

Second part is the variable name: motor_power wich we can then use in our scripts as getVar('motor_power')


You can see the controls are seperated by several different charecters, the function does not care which ones are used, it will only acknowledge standard charecters(letters and numbers), the rest will be only used to determine seperation.

So if you write:

k(A) + j(A) ---------------- motor_power

or

k/A j/A *************** motor_power

or

k A j A /////////////////// motor_power

the function will see them as the exact same thing, and will work the same way.


So you can create any form of seperations, like it's made in the example, to make the controls easily recognizable.

Advertisement