• Login
sketchucation logo sketchucation
  • Login
ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

Oscillator script

Scheduled Pinned Locked Moved SketchyPhysics
9 Posts 3 Posters 1.1k Views 3 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.
  • W Offline
    Wacov
    last edited by 9 May 2009, 21:13

    Seems I'm making one for everything now. This may seemed over-engineered, but the crucial thing is that this is CONTROLLABLE! I've made it as user-friendly as I can, so to change the cycle rate, just change the local variable 'rate' at the top of the script. To make it controllable, which is, ultimately, the point, you can use joystick, slider, button or key entry to change 'rate'. There's also room for expansion, using your own script to control the rate. The output of the script is a variable called "pos", and, if the line breaks are removed, this should work straight from a joint's controller box. Could well be useful in the upcoming SP challenge, so, here it is:

    rate=50;
    
    if frame==0;
    setVar("pos",0.5);
    setVar("direct",1);
    end;
    
    if getVar("pos")>1.0;
    setVar("direct",0);
    elsif getVar("pos")<0.0;
    setVar("direct",1);
    end;
    
    if getVar("direct")==1;
    getSetVar("pos",getVar("pos")+(1.0/rate));
    else;
    getSetVar("pos",getVar("pos")-(1.0/rate));
    end;
    

    This wasn't hard to write, so I don't really want or expect any credit. Use and spread freely!

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

    1 Reply Last reply Reply Quote 0
    • B Offline
      BTM
      last edited by 9 May 2009, 22:19

      Nice, but I won't be needing it; my (probable) entry uses keyboard input only, so I have it working fine. πŸ˜‰
      ...I might as well throw in a small contribution from my model:

      if key("space")==1 then setVar("timer",frame+3);end;
      
      if frame<=getVar("timer") and key("space")==0 then setVar("jump",1);else setVar("jump",0);end;
      

      that up there is a jump code. When you let go of the spacebar, jump will be set to 1 for 3 frames. A jump code that did that when space was pressed was a little too long and tricky to write, so I made this one. Having it jump after the key is let go also allows for a "wind up" while it's pressed πŸ˜‰

      oh, question for wacov: why do you use semicolons all the time, instead of then and and? I find using words makes it easier for others (and myself on occasion) to understand with a quick glimpse.

      1 Reply Last reply Reply Quote 0
      • B Offline
        BTM
        last edited by 9 May 2009, 22:51

        ..speaking of quick glimpses, here's one for you 😎 Not my most recent version, but should give you an idea.
        [flash=480,300:2v6x2t0v]http://content.screencast.com/users/sketchupBTM/folders/Jing/media/57eec274-eaa0-44be-a571-1adbe863b1c7/jingswfplayer.swf[/flash:2v6x2t0v]

        ...Can a moderator fix that flash πŸ˜’? I put in the right adress from the embeded src, I THINK, but...

        ...(sigh)... here's the link. http://www.screencast.com/t/ZyU2omCfC2A

        1 Reply Last reply Reply Quote 0
        • C Offline
          CPhillips
          last edited by 10 May 2009, 05:34

          Thats an amazing model BTM! I cant wait until its finished.

          I dont know why the flash isnt working. But I'll see if I can fix it....

          1 Reply Last reply Reply Quote 0
          • C Offline
            CPhillips
            last edited by 10 May 2009, 05:39

            Thats a good oscillator script. But I should point out that it isnt exactly the same as the built in one. That one is based of a sine wave. So the object slows down smoothly at either end of the period. But for most applications this is probably just as good.

            I am going to try to make it so you can package up useful scripts like this and reuse them easier.

            1 Reply Last reply Reply Quote 0
            • W Offline
              Wacov
              last edited by 10 May 2009, 07:41

              I use semi-colons because it's slightly shorter to write, and it's (I think) good practice to use them at the end of every line. Also means you can take out the line breaks without a problem.

              BTM, your link doesn't work for me? 😞

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

              1 Reply Last reply Reply Quote 0
              • B Offline
                BTM
                last edited by 10 May 2009, 10:29

                The link works fine for me. I don't know if you need flash player installed though, so yeah...

                1 Reply Last reply Reply Quote 0
                • W Offline
                  Wacov
                  last edited by 10 May 2009, 11:39

                  Ok, works now. That's awesome! Well done

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

                  1 Reply Last reply Reply Quote 0
                  • B Offline
                    BTM
                    last edited by 11 May 2009, 01:06

                    ... Something else that may be included...

                    [flash=320,200:17g34xur]http://content.screencast.com/users/sketchupBTM/folders/Jing/media/40aec8da-d5f1-4f37-9730-b59356b28a68/jingswfplayer.swf[/flash:17g34xur]

                    Again with the broken flash, sorry,
                    http://www.screencast.com/t/iy4gqmsMbNW

                    So far I've been just messing around with ideas for my character (The robot may just be temporary; it's pretty basic and square),but here are some of it's "stats" if you will.

                    Picture 1.png
                    ...I think I might improve the running speed, but it messes up the leg/ arm movement a bit too much πŸ˜•
                    I've also been thinking about adding "kick" to the list, but the codes seem complex enough as it is πŸ‘Š

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

                    Advertisement