jueves, 31 de octubre de 2013

Frank's guide to sweet suspension

Postby Frank » Tue Sep 14, 2010 5:49 am
This is a guide, constructed of many generally stand-alone articles, on how to construct suspension that will help a wheeled car zoom over bumps and various obstacles quickly and efficiently. If you're looking for tips intended for slowly crawling over extreme obstacles, there probably isn't much of value in here. I'm hoping this guide comes out useful to a wide range of skill levels. It's primarily intended for people who have already built at least a few cars, though.

If you're attracted to a game like this, you probably know what spring damping is, but not everyone does and not everyone knows how to use it best. Damping is essentially how much energy the spring dissipates. You'd probably want extremely low damping in clockwork, where efficiency is extremely important. Suspension usually needs pretty high damping, unless you want your car to bounce a lot. Maxing out the damping on the springs in your suspension isn't always a good idea, though. Too much can make it kinda sluggish and hard. If the damping and spring strength are too high relative to the mass of objects they're attached to, the physics will also freak out and vibrate and/or explode. Every car and every design has its own optimum damping properties, and what works for one course may not work perfectly for any other even on the same car.

Why Pistons Suck

The long and short of it is that piston-based suspension breaks. It's the only real problem, but it's a killer. Algodoo runs at only 100 frames per second. Because of this, sudden jolts can move one part outside of the other in just one time step, and no collision is registered. Or, slower but more powerful forces can simply push one object through another. Anything that relies on collisions to hold it together is going to break if it gets hit hard enough. Building bulky pistons can help this problem a lot, but they can never be indestructible. Increasing the frequency that Algodoo runs at can help this a lot, but it increases lag and may cause many scenes to work differently.

Better Alternative to Piston Suspension
So you read the above about how piston-based suspension is fragile, and now you're thinking, "OK, so how the hell can I make suspension without some kind of piston?" Your best bet is torsion bars. The idea is simple. You put the wheel on one end of a stick, you hinge the other end of the stick to the body, and you use a spring or something to hold it in place. The design, angle, and placement of a torsion bar can have as much influence on its performance as the spring. Build it wrong, and you'd be better off without any suspension at all. Build it right, and it will let you zip over huge bumps like they aren't there, or even help your car get over obstacles that would normally be impossible.

Unsuspended Weight and Center of Gravity

Unsuspended weight is the amount of mass that isn't on top of your suspension. It's a bad thing. Making your wheels and other suspension parts heavy will give you very clunky and sluggish suspension that, to a certain extent, defeats the purpose of suspension. The point is to cruise over bumps without influencing the momentum of the car. If a quarter of the car's mass stops going forward and gets redirected upwards every time the front wheel hits a bump, it isn't doing much good.
On the other hand, making all of the lowest parts of the car very light will raise the car's center of gravity and give it trouble on hill climbs and generally be more likely to land on its top. A low center of gravity can be achieved without harming the suspension by using small weighted blocks in the frame and keeping the rest of the car as light as possible.

Ideal Front Suspension
This guide assumes a two-wheeled car. All the same principles apply to more complicated systems, though. Your front wheel should be the first thing that hits a bump. Your front suspension is responsible for the hardest part of getting over an obstacle, getting your center of gravity on top of it. It has the full mass of the car pushing on it when it hits bumps. It isn't normally the primary power source of the vehicle. Because of these factors, it needs to be light and soft and capable of giving and resetting very quickly. One of the most effective features that can be built into front suspension is the tendency to move back as it moves up. An obstacle that takes a quarter of a second to get over will stop your whole car without this feature, but if the suspension has some front-to-back give, the front wheel can take a little time trying to get over it without slowing down the rest of the car.
With pistons, this is easy. Just tilt it a little, and life is good. It's a little trickier with torsion bars. Ideally, the torsion bar is hinged above and in front of the wheel, letting it swing up and back when it hits something. Unfortunately, not every car design makes this possible. When it isn't, behind will work as long as it's not far from horizontal. Another thing to do is build some give into where the bar hinges to the frame. I've had the most success with putting the torsion bar on another, vertical torsion bar. Vertical motion is handled by the bar attached to the wheel, and horizontal forces are handled by the vertical one. Hinge suspension techniques work well in that application.

Ideal Rear Suspension
The back wheel faces a simpler task. By the time it hits a bump, it has the whole weight of the car pulling it over. Effective power transmission is much more important for the rear suspension, too. While it's still a good idea to angle the torsion bar above and in front of the wheel, the best angle for rear suspension is much closer to horizontal than for front suspension. When the car is accelerating, you don't want the forward force of the wheel to get translated into upward force by a high-angled torsion bar. That will make it jump a bit and seriously reduce the accelerating ability of the car, and also cause a hell of a lot of trouble on a hill climb. A little bit of side-to-side play can help some, but it should not be added if it reduces the grip of the wheel.
For rear suspension, it's OK to be a little clunky. Light weight isn't quite as important, and power transmission shouldn't be seriously sacrificed for anything. The momentum of the car will do a lot to help the rear wheel get over things.

Soft Wheels

Soft wheels have their applications. They can do a lot of the little fast and sharp bumps with efficiency you could never get out of the main suspension. The problems are that they can reduce the traction of the wheel, many designs can get broken or tangled, and they often don't perform well at high speeds. There is only one basic design that I have ever found entirely satisfactory: an extremely low-density circle hinged in multiple places to an overlapping, smaller, regular-density circle. The smaller circle produces/transmits the power and only the larger circle normally makes contact with the ground. If both circles are aligned perfectly with each other, this design has no issues at reasonably high speeds and never breaks. It can still have grip issues, though, depending on how it's calibrated. I rarely doubt whether this design is better than an equivalent hard wheel, but I'm always asking myself that kind of question when I try other designs.

Adding transmission to a suspension setup isn't actually that hard. A drive shaft built from three or four evenly spaced connecting rods can double as a torsion bar. A joint can be built by making a drive shaft to a circle, and then building another drive shaft from that circle to the wheel that needs power. With a joint in the drive shaft, it becomes possible to add some front-to-back give.

Building the Indestructo-Car
The key to making an extremely tough car is ensuring that no part has more than one possible resting position. Pistons have many: one spot inside the track, and a whole circle of positions once the sliding part gets knocked out. And it will get knocked out. Torsion bars usually have two: one with the wheel where it belongs, and another with the wheel usually sticking up instead of down. Depending on design factors, a few other funky angles are possible. You don't want this happening, so there are a couple of ways to ensure it can't.
One way is to build the springs so that they only reach a balance when the wheel is where it belongs. The easiest way is to use only one spring with zero target length, but not every car design makes it possible to do that. Multiple springs with non-zero length can work too, and it isn't hard to do, but the mechanics of achieving it are hard to explain.
Another way is to use a non-colliding chain to limit the range of motion in the torsion bar, so that it can't ever get knocked into the second resting position of the spring. A chain can also be used to make it impossible for the suspension to bottom out.

This guide may or may not be added and modified over time, depending on whether I notice any flaws or reader requests/corrections. Here is a list of some very successful cars I made while learning these principles.

Probably my favorite car ever. Smooth suspension includes chains, soft wheels, and lots of front-back motion. Hull design and center of gravity are great for landing and staying on its feet.

Demonstrates transmission and suspension working together. Also abuses Algodoo's physics to get optimal power out of a hinge with very limited energy, but I'm not saying how.

It's not a wheeled car, but it demonstrates the principles of torsion bar positioning well. The hull is designed to help it get over tall obstacles.

how to make a black hole bullet

Postby coleyy » Sat Sep 25, 2010 11:00 pm
A black hole bullet is a bullet that creates a black hole when it touches something.to create one, make a normal spring bullet, then go to the script menu and copy and paste this:
    e.this.density = +inf;
    attraction = 500000;
    killer = true;
    collisionset = 127
in the oncollide. its actually pretty easy

For function

Re: [Help] "FOR" function

Postby Kilinich » Mon Mar 12, 2012 12:39 pm
Buil-in "for":
It's function for(n, what) with 2 arguments:
1) integer - number of iteration
2) function - function which you need to call few times with one argument - number of call


scene.my.show = (i) => {scene.addbox({pos := [i,0]; text := (""+ i)})};
for(5, scene.my.show);
Dream of Algodoo as game development engine...
User avatar
[Best bug reporter 2010]
Posts: 1502
Joined: Mon Aug 31, 2009 8:27 pm
Location: South Russia

Strings functions

Timer. Alarm. Event

Timer, Alarm, Event. Easy.

Postby Kilinich » Sun Jan 17, 2010 11:23 pm
screenshot of the scene
Rating: rated 6.7
Filesize: 1.94 kB
Comments: 7
Ratings: 5

Key feature is every-frame evend handler "Scene.my.event" that can be attached to any global property.
For example: 
App.Background -> {
    cloudOpacity = {Scene.my.event(0.94999999)};

And this is all the rest:

Scene.my.event := (n)=>{Scene.my.evHandle; n};
Scene.my.newAlarm := (aTime, aWhat)=>{
    Scene.my.events = Scene.my.events ++ [[aTime, 0, 1]];
    Scene.my.eventsCount = Scene.my.eventsCount + 1;
    Scene.my.actions = Scene.my.actions ++ [aWhat];
Scene.my.newEvent := (eTime, eRepeat, eCount, eAction)=>{
    Scene.my.events = Scene.my.events ++ [[eTime, eRepeat, eCount]];
    Scene.my.eventsCount = Scene.my.eventsCount + 1;
    Scene.my.actions = Scene.my.actions ++ [eAction];
Scene.my.newTimer := (tTime, tWhat, tRepeat)=>{
    Scene.my.events = Scene.my.events ++ [[tTime + sim.time, tTime, tRepeat ? 9999999 : 1]];
    Scene.my.eventsCount = Scene.my.eventsCount + 1;
    Scene.my.actions = Scene.my.actions ++ [tWhat];
Scene.my.delEvent := (i)=>{
    newActions = [];
    newEvents = [];
    Scene.my.eventsCount = Scene.my.eventsCount - 1;
    for(i, (n)=>{
        newActions = newActions ++ [Scene.my.actions(n)];
        newEvents = newEvents ++ [Scene.my.events(n)]
    for(Scene.my.eventsCount - i, (n)=>{
        newActions = newActions ++ [Scene.my.actions(n + i + 1)];
        newEvents = newEvents ++ [Scene.my.events(n + i + 1)]
    Scene.my.events = newEvents;
    Scene.my.actions = newActions
Scene.my.eventsCount := 0;
Scene.my.events := [];
Scene.my.actions := [];
Scene.my.evHandle := {
    sim.running ? {
        DelEvents = [];
        DelCount = 0;
        Scene.my.frame = Scene.my.frame + 1;
        for(scene.my.eventsCount, (ev)=>{
            scene.my.events(ev)(0) < sim.time ? {
                Scene.my.events(ev)(2) > 1 ? {
                    newEvents = [];
                    for(ev, (n)=>{newEvents = newEvents ++ [Scene.my.events(n)]});
                    newEvents = newEvents ++ [[scene.my.events(ev)(1) + sim.time, scene.my.events(ev)(1), scene.my.events(ev)(2) - 1]];
                    for(Scene.my.eventsCount - ev - 1, (n)=>{newEvents = newEvents ++ [Scene.my.events(n + ev + 1)]});
                    Scene.my.events = newEvents
                } : {
                    DelEvents = DelEvents ++ [ev];
                    DelCount = DelCount + 1
            } : {}
        for(DelCount, (ev)=>{scene.my.delEvent(DelEvents(ev))})
    } : {}
Scene.my.timers := [];
Scene.my.frame := 0;
Last edited by Kilinich on Fri Jun 04, 2010 8:26 pm, edited 2 times in total.
Dream of Algodoo as game development engine...
User avatar
[Best bug reporter 2010]
Posts: 1502
Joined: Mon Aug 31, 2009 8:27 pm
Location: South Russia

Laser on of

Re: Laser on/off

Postby hiltropper » Sun Apr 17, 2011 11:30 pm
just turn the fadedist from 0 to something more than 0 (like 25)
laser : fadedist = {scene.my.fade}
scene.my.var1 ? {scene.my.fade=0}:{scene.my.fade=25};

Other, this, geom

Re: oncollide .other / .geom / ....

Postby electronicboy » Sun Jun 12, 2011 7:10 pm
e means event.

I have a post somewhere that explains what it all means, if I find it I will quote or link it.

I cant find that post.

the layout for thyme commands thats affect variables:


This is a list of the "adresses" and what they do:

Other - used on geometry colisions (oncollide) - this is used to adress the OTHER object in a collision (not the one with the code on)

THIS - used on geometry collisions (oncollide) - this is used to adress THIS object (the object with the code on)

Geom - used in laser hits (onlaserhit) - this is used to adress the geometry in a laser collision

laser - used in laser hits (onlaserhit) - this is used to adress the laser in a laser collision

----object variables----

The next part is to "address" to a variable.
To see these variable just create an object and look at the script menu ;)
Or check THIS POST of [Thyme][1.5.61]Thyme Command/Variables List

E.other.density = 5

this Means,
Set the density of the OTHER object (one without the code) to 5

If you need any more help with this, just ask, I or others may be willing to answer
Or even check
[Tutorial]Thyme Tutorial - With explanations at every step
skype: sf.electronicboy
-Network connection fixed, DSL... :/
Posts: 1429
Joined: Mon Aug 31, 2009 6:18 pm
Location: Preston,UK


scene.my.bla = {geval("(cos(sim.time))")}

Postby bozbez 

Postby Kilinich » Mon Jan 10, 2011 2:51 am
scene.my.rnd := {(system.time+ sin(sim.tick))%1}

Láser color oncollide

The script you want is this:
e.laser.color = e.geom.color

When it goes into the onLaserHit or onHitByLaser box, it should look like:
(e)=>{e.laser.color = e.geom.color}

Condicionales . Or. And

OnLaserHit := (e)=>{ (scene.my.motor1 && scene.my.motor2) ? {scene.my.motor3 = true} : {scene.my.motor3 = false} }

scene.my.motor3 = (scene.my.motor1 && scene.my.motor2)

By Daniels220

Scene.my.variable1 == 0 || scene.my.variable1 == 100 ?{scene.my.variable2 = "Hello"}:{scene.my.variable1 + scene.my.random}

Re: the opposite of && if structure?

Postby Kilinich » Thu Oct 28, 2010 9:56 pm
from http://www.phunland.com/wiki/Thyme. * Conditions — x ? y : z (x = condition, y = if true, z = if false) * Equal — x == y * Not equal — x != y * Greater than — x > y * Greater than or equal — x >= y * Less than — x < y * Less than or equal — x <= y * Addition — x + y * Subtraction — x - y * Multiplication — x * y * Division — x / y * Modulus — x % y * Power of — x ^ y * Negate — -x * Boolean NOT — !x * Boolean AND — x && y * Boolean OR — x || y * List addition — x ++ y
Dream of Algodoo as game development engine...
User avatar Kilinich
[Best bug reporter 2010]
Posts: 1502
Joined: Mon Aug 31, 2009 8:27 pm
Location: South Russia

You an use an IF statement.


 e.other.color(0) == 1 ? {e.other.color = [0, 0, 0, 0]; e.other.collideSet = 0;} : {}
This will cause the ball to make objects disappear and cease to collide with anything if the red component of their color is one.  You might want to do this mechanically, though.  One time I entered a bomb contest in which the targets were hinged to a giant invisible killer block that was on an obscure collision set.  Once the blocks got knocked loose, they started colliding with the killer and were deleted.  Either way, there's no worry about overcounting the score, because each peg would only be able to be touched once.