How to spawn hinges, fixates, and springs
Posted: Wed Oct 21, 2009 12:32 am
Spawning hinges, fixates, or springs is actually quite easy.
You can either enter the following codes into an onCollide, onLaserHit, or the console. Press ~ or F11 to bring down the console and type in there.
How to spawn hinges
You need to know the geomID of the first and second objects that are going to be attached. Let's start with some control circles.
That will give us our circle with a preset geomID of 1. We will now do this again to get our second circle.
This gives us our second circle with a geomID of 2. 0In order for them to be hinged together they need to be on top of each other.
You should have something like this:
Now that we have our two circles with known geomID's we can spawn a hinge. To spawn a hinge you need to have the geomID of the object that will have something being attached to, the geomID of the object that is to be attached, and the position at which the hinge will spawn.
geom1 is the geomID of the first object. geom0 is the geomID of the second object. world0pos is the position at which the hinge will be spawned. This script will spawn a hinge connecting both circles at the mouse point.
This is what you should have now:
How to spawn fixates
Spawning a fixate is about the same as spawning a hinge.
Using our control circles we will spawn a fixate by using this script:
geom1 is the geomID of the first object. geom0 is the geomID of the second object. world0pos is the position at which the fixate will be spawned. This will spawn a fixate that connects the two circles at the mouse point.
This is what you should have now:
Sorry that this wasn't as long. It's only this short because it's about the same as spawning a hinge. c:
How to spawn springs
In order to spawn a spring you need to know the geomID of the first object, the geomID of the second object, the position of the first object, and the position of the second object. Using our control circles we will spawn a spring connecting the two.
(control circles for spring)
geom1 is the geomID of the first object. geom0 is the geomID of the second object. world0pos in this case is the position of geom1. world1pos is the position of geom0. Keep in mind that you can alter the values of the spring when you spawn them. You can change the constant(strength) by adding ;constant := number you want. You can change the dampingFactor(damping) by adding ;dampingFactor := number you want. You can change the length of the spring by adding ;length := number you want.
You should now have something like this:
You can either enter the following codes into an onCollide, onLaserHit, or the console. Press ~ or F11 to bring down the console and type in there.
How to spawn hinges
You need to know the geomID of the first and second objects that are going to be attached. Let's start with some control circles.
- Code: Select all
scene.addCircle({pos := app.mousePos; geomID := 1})
That will give us our circle with a preset geomID of 1. We will now do this again to get our second circle.
- Code: Select all
scene.addCircle({pos := app.mousePos; geomID := 2})
This gives us our second circle with a geomID of 2. 0In order for them to be hinged together they need to be on top of each other.
You should have something like this:
Now that we have our two circles with known geomID's we can spawn a hinge. To spawn a hinge you need to have the geomID of the object that will have something being attached to, the geomID of the object that is to be attached, and the position at which the hinge will spawn.
- Code: Select all
scene.addHinge({geom1 := 1; geom0 := 2; world0pos := app.mousePos})
geom1 is the geomID of the first object. geom0 is the geomID of the second object. world0pos is the position at which the hinge will be spawned. This script will spawn a hinge connecting both circles at the mouse point.
This is what you should have now:
How to spawn fixates
Spawning a fixate is about the same as spawning a hinge.
Using our control circles we will spawn a fixate by using this script:
- Code: Select all
scene.addFixJoint({geom1 := 1; geom0 := 2; world0pos := app.mousePos})
geom1 is the geomID of the first object. geom0 is the geomID of the second object. world0pos is the position at which the fixate will be spawned. This will spawn a fixate that connects the two circles at the mouse point.
This is what you should have now:
Sorry that this wasn't as long. It's only this short because it's about the same as spawning a hinge. c:
How to spawn springs
In order to spawn a spring you need to know the geomID of the first object, the geomID of the second object, the position of the first object, and the position of the second object. Using our control circles we will spawn a spring connecting the two.
(control circles for spring)
- Code: Select all
Scene.addSpring({geom1 := 1; geom0 := 2; world0pos := [-31.396013, 5.9814367]; world1pos := [-29.41792, 7.3022513]; size := 0.5})
geom1 is the geomID of the first object. geom0 is the geomID of the second object. world0pos in this case is the position of geom1. world1pos is the position of geom0. Keep in mind that you can alter the values of the spring when you spawn them. You can change the constant(strength) by adding ;constant := number you want. You can change the dampingFactor(damping) by adding ;dampingFactor := number you want. You can change the length of the spring by adding ;length := number you want.
You should now have something like this: