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

    All known scripts

    Scheduled Pinned Locked Moved SketchyPhysics
    30 Posts 8 Posters 3.5k Views 8 Watching
    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.
    • P Offline
      Physicsguy1
      last edited by

      could everyone who has any scripts please contribute them? It would be very helpful. I know that -(a)*50 can be used for emitting guns, [0,2,3,4,5][(frame/50)%5] can be used for timed and automatic machine movement. If you do know any, are there other variants which do the same action? and is it possible to figure out new scripts? I think, to my knowledge, that it doesn't affect the actions if you switch around[0,2,3,4,5][(frame/50)%5] to [(frame/50)%5][0,1,2,3,4,5]. Please help. I need some of these scripts for a project

      1 Reply Last reply Reply Quote 0
      • P Offline
        phy
        last edited by

        key('x') or z/q/r/anything in place of x for keyboard

        Tableau de comparaison de Staxyn s'agit d'un mГ©dicament uniquement sur ordonnance.

        1 Reply Last reply Reply Quote 0
        • P Offline
          phy
          last edited by

          key('r')-key('f') acts the same as(0.5-rightx)on a motor

          Tableau de comparaison de Staxyn s'agit d'un mГ©dicament uniquement sur ordonnance.

          1 Reply Last reply Reply Quote 0
          • C Offline
            CPhillips
            last edited by

            @unknownuser said:

            could everyone who has any scripts please contribute them? It would be very helpful. I know that -(a)*50 can be used for emitting guns, [0,2,3,4,5][(frame/50)%5] can be used for timed and automatic machine movement. If you do know any, are there other variants which do the same action? and is it possible to figure out new scripts? I think, to my knowledge, that it doesn't affect the actions if you switch around[0,2,3,4,5][(frame/50)%5] to [(frame/50)%5][0,1,2,3,4,5]. Please help. I need some of these scripts for a project

            Actually switching the order will not work in this case.

            1 Reply Last reply Reply Quote 0
            • B Offline
              Bigbjason
              last edited by

              @unknownuser said:

              I know that -(a)*50 can be used for emitting guns, [0,2,3,4,5][(frame/50)%5] can be used for timed and automatic machine movement.

              Can someone explain to me how to use these two scripts?

              1 Reply Last reply Reply Quote 0
              • W Offline
                Wacov
                last edited by

                @bigbjason said:

                @unknownuser said:

                I know that -(a)*50 can be used for emitting guns, [0,2,3,4,5][(frame/50)%5] can be used for timed and automatic machine movement.

                Can someone explain to me how to use these two scripts?

                Scripts can go in any of the blue boxes in the UI, while you have a joint or group selected. The 'Controller' box for joints controls the joint; normally this needs a script that results in a value between 0.0 and 1.0, but you can have any value you like (with unexpected results). If you include them in boxes in the 'Properties' section, they'll control emitter/thruster/magnet settings. In these boxes you can use any combination of fixed settings/ scripts... for example, to have a controlled emitter, you could have a setting of 20 in the 'rate' box (fires every 20 frames) and a script of "key('space')*100" in the strength box (this would fire when you press space, with a force of 100). The 'Lifetime' setting isn't a blue box; this means it has to be determined before the simulation starts. Leaving it at 0 would mean the emitted objects stay for the remainder of the simulation, but any number over this determines the number of frames the object survives for.

                To use the script Physicsguy describes ([0,2,3,4,5][(frame/50)%5]), you should understand what it does; the first [] holds the list of values the script cycles through, and the second [] tells it how often to change (In this case, every 50 frames). The %number resets it to the beginning when it's done, with the number being the number of values (5).

                I thought I'd add the IF function to this; it's pretty versatile, and for those that don't know, it performs a logical test that results in an answer of 'True' or 'False'. Here's an example:

                if(key('space')==1.0);2.0;else;0.5;end

                This asks if the input from the spacebar is 1.0 (being pressed). If it is (True), it returns a value of 2.0 . If it isn't (False), it returns 0.5 .

                You can also use else-IF. So:

                if(key('space')==1.0);2.0;elsif(key('a')==1.0);0.0;else;0.2;end

                Notice that it's spelt 'elsif', without an 'e'. This returns 0.2 by default. If a is pressed, it returns 0.0, and if space is pressed, 2.0 . The space will 'override' a, so if both are pressed, it will still return 2.0 . As far as I know, you can use as many 'elsif's as you like. You can also put scripts, like Physicguy's, as the values returned by the IF function.

                If anyone doesn't understand this, don't worry, just ask. I hope this helps! 😄

                http://sketchup.google.com/3dwarehouse/cldetails?mid=3096a836877fb9af6cd8ad826e9017b8&prevstart=0

                1 Reply Last reply Reply Quote 0
                • B Offline
                  BTM
                  last edited by

                  Wow. I'm as confused as I'll ever be. I now understand how to write if's, but don't know what they do. I'll have to find out later...
                  Oh, simple question: How do you make a controller control the speed of an oscillator?

                  I've tried some basics scripts I though might work, as I have no knowledge of scripts whatsoever, and have gotten some pretty... uh... interesting results
                  (like the object connected to the oscillator flying away when I press the up arrow, and returning when I let go, unless it comes in contact with another object. Then it disappears.)

                  I'm guessing I'd have to use the math.sin (or whatever it was, I forget) script and edit it for it to work, but first I need to know how it works in the first place.

                  1 Reply Last reply Reply Quote 0
                  • W Offline
                    Wacov
                    last edited by

                    Try "oscillator(slider("controller")*50)". Unfortunately, it won't work the way either of us want it to (it resets to the start position every time the controller is changed) To be honest, I'm not an expert... everything I knew about IF functions went into that post 😄

                    Basically, all the IF does is ask if something's true or false. A simple 'question' would be:
                    (1.0<0.5)
                    This checks whether 1.0 is less than 0.5. Obviously, it's not, so that would result in a false. In the script, you have the question, then what value to return if it's true, then what value to return if it's false (The value can itself be another script, but let's not get into that 😄 ) So, if the value for true is "1.0", and the value for false is "0.0", then our script of:

                    if(1.0<0.5);1.0;else;0.0;end

                    Would return the false value of "0.0" as the controller for the joint, or whatever you're controlling. (the ";" separates what, in a normal script, would be line breaks)

                    Some stuff for the question:
                    "<" = Less than
                    ">" = Bigger than
                    "==" = Equal to
                    "<=" = Less than or equal to
                    ">=" = Bigger than or equal to

                    http://sketchup.google.com/3dwarehouse/cldetails?mid=3096a836877fb9af6cd8ad826e9017b8&prevstart=0

                    1 Reply Last reply Reply Quote 0
                    • C Offline
                      CPhillips
                      last edited by

                      Thats a very good summary of the current scripts Wacov.

                      Right off the bat I dont know how to do an oscillator that the rate is controlled. Let me think about it....

                      1 Reply Last reply Reply Quote 0
                      • B Offline
                        BTM
                        last edited by

                        Wacov; your script changes the distance to larger, and speed to slower, the more you move it left.

                        ...So here's a model with a few tries at changing speed only. right one is just plain oscillator(50), middle one works best, but is reversed for some reason, and the order can't be reversed. one on the left is the one that, to me, makes no sense at all, and I think it's a bit funny so I posted it.
                        test_session.skp
                        NOTE: use arrow keys.

                        1 Reply Last reply Reply Quote 0
                        • B Offline
                          Bigbjason
                          last edited by

                          @wacov said:

                          To use the script Physicsguy describes ([0,2,3,4,5][(frame/50)%5]), you should understand what it does; the first [] holds the list of values the script cycles through, and the second [] tells it how often to change (In this case, every 50 frames). The %number resets it to the beginning when it's done, with the number being the number of values (5).

                          Ok, I think I understand most of it. The first set of []s are the slider values, if there was a slider et the frame/50 tells it to move from 0 to 2 in 50 frames et from 2 to 3 in 50 so forth et the %5 the number of values there are, but on one model there are 9 values but it is %8. Why is this? Will it leave of the last value or skip the first one? Et how do I know when 50 frames are up, like is there a frame counter or something somewhere? I see on some videos there is a thing like Frame 230/410, could this be what I need?

                          1 Reply Last reply Reply Quote 0
                          • C Offline
                            CPhillips
                            last edited by

                            I guess I broke the bit that shows the frame number. Its fixed in next release.

                            1 Reply Last reply Reply Quote 0
                            • C Offline
                              CPhillips
                              last edited by

                              These are really good questions!

                              Here are some more tips for those trying to understand scripts:

                              Formulas/Scripts are really just little pieces of Ruby script. The underlying script on Sketchup.

                              Here is a online Ruby tutorial. Most of what is in the tutorial you dont need to know to do SP but the more you know about Ruby the better your scripts could be.

                              http://tryruby.hobix.com/

                              One cool thing about that site is you can use it to test some of your formulas. Reload the site:
                              http://tryruby.hobix.com/

                              But dont do the tutorial. Just type the following. Enter each line one at a time:

                              
                              frame=5
                              [5,4,3,2,1,0][frame/5]
                              frame=20
                              [5,4,3,2,1,0][frame/5]
                              

                              At each step you should see the results. And you can test out what value is used when the frame is 5 and 20.

                              But even better is you can do the same thing inside Sketchup. Just go to Window->Ruby Console and then type the lines one at a time inside and you will see the same result.

                              Some formulas wont work in the console or on the tutorial site. joystick, keyboard and most other things that use() wont work. But I think I can make a preview formula section in the dialog that will work.

                              One other thing. Most (if not all) the blue script fields can be edited while the simulation is running. This makes it a lot easier to fine tune formulas.

                              For example:Create working emitter with some strength. Press play. Now adjust the emitter strength and then click out of the strength script field and the new emitter strength change should take place right away.

                              I still haven't figured out how to make a variable speed oscillator forumla.

                              1 Reply Last reply Reply Quote 0
                              • W Offline
                                Wacov
                                last edited by

                                @unknownuser said:

                                Wacov; your script changes the distance to larger, and speed to slower, the more you move it left.

                                ...So here's a model with a few tries at changing speed only. right one is just plain oscillator(50), middle one works best, but is reversed for some reason, and the order can't be reversed. one on the left is the one that, to me, makes no sense at all, and I think it's a bit funny so I posted it.
                                [attachment=0:xf9qtpt5]<!-- ia0 -->test_session.skp<!-- ia0 -->[/attachment:xf9qtpt5]
                                NOTE: use arrow keys.

                                Hmmm... I don't think the distance is less, it's just the joint trying to keep up with the oscillator, which is changing direction before the joint can get where it's supposed to be. Yours is better, but it it still spazzes out when you use a slider or joystick for the control 😄

                                Just hope Chris comes up with something, or there won't be any controllable walkers...

                                http://sketchup.google.com/3dwarehouse/cldetails?mid=3096a836877fb9af6cd8ad826e9017b8&prevstart=0

                                1 Reply Last reply Reply Quote 0
                                • B Offline
                                  BTM
                                  last edited by

                                  @wacov said:

                                  Hmmm... I don't think the distance is less, it's just the joint trying to keep up with the oscillator, which is changing direction before the joint can get where it's supposed to be. Yours is better, but it it still spazzes out when you use a slider or joystick for the control 😄

                                  Just hope Chris comes up with something, or there won't be any controllable walkers...

                                  What spazzes? I didn't see any issues, well except that when the speed is changed it goes back to the original position, if that's what you mean.

                                  1 Reply Last reply Reply Quote 0
                                  • W Offline
                                    Wacov
                                    last edited by

                                    That is what I mean... it makes it effectively unusable for anything involving dynamic, analogue input. I can't see there being a way around this without delving into the fabric of sketchyphysics, so just leave it to Chris.

                                    http://sketchup.google.com/3dwarehouse/cldetails?mid=3096a836877fb9af6cd8ad826e9017b8&prevstart=0

                                    1 Reply Last reply Reply Quote 0
                                    • B Offline
                                      BTM
                                      last edited by

                                      I think this might be the first controllable sketchyphysics walker... I call it: the FunnyWalker. You'll see why. Use W and S, and the up and down arrows, to control it. NOTE: controls are reversed for speed (I don't know why, and there was no way of fixing it). Don't use a joystick, because it will be a bit messed up if you do.
                                      walkertest2.skp
                                      I did cheat a bit by using a gyro though 😳

                                      1 Reply Last reply Reply Quote 0
                                      • W Offline
                                        Wacov
                                        last edited by

                                        Whaddya mean, no way to fix it?!? oscillator(50/(-righty+1)) does the trick nicely 😄

                                        Good walker, shame about the joysticks

                                        http://sketchup.google.com/3dwarehouse/cldetails?mid=3096a836877fb9af6cd8ad826e9017b8&prevstart=0

                                        1 Reply Last reply Reply Quote 0
                                        • K Offline
                                          klaufi
                                          last edited by

                                          controllable oscillators:

                                          Math.sin(frame/(10*slider('speed')))/3.0

                                          just an example, numbers are replacable, also you can add constants, use Math.cos or use keys and so on

                                          1 Reply Last reply Reply Quote 0
                                          • B Offline
                                            BTM
                                            last edited by

                                            I thought It would be possible with a math.sin script! 😄 Thanks!
                                            ...Now anyone here want to explain how to use math.sin, or math.cos, or any other scripts of that type, so I can customize it?

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

                                            Advertisement