Page 1 of 2

How to spawn hinges, fixates, and springs

PostPosted: Wed Oct 21, 2009 12:32 am
by standardtoaster
Spawning hinges, fixates, or springs is actually quite easy. :D

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:
Image

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:
Image

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:
Image

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)
Image

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:
Image

Re: How to spawn hinges, fixates, and springs

PostPosted: Wed Oct 21, 2009 3:49 am
by niffirg1
Wow this is amazing
Did not know how to do this until now

Re: How to spawn hinges, fixates, and springs

PostPosted: Wed Oct 21, 2009 6:16 am
by KarateBrot
Cool tutorial. I like tutorials with images :thumbup:
Maybe you could also add the tip to type the script codes into the console if anyone doesn't know of other things than OnCollide.

Re: How to spawn hinges, fixates, and springs

PostPosted: Wed Oct 21, 2009 7:37 am
by standardtoaster
Right, I forgot about that. :lol: I'll edit that next week or so.

Re: How to spawn hinges, fixates, and springs

PostPosted: Wed Oct 21, 2009 7:24 pm
by RA2lover
also, maybe teaching the users to spawn it on existing geometries by using New Method

Re: How to spawn hinges, fixates, and springs

PostPosted: Tue Oct 27, 2009 1:37 am
by standardtoaster
I would do that, but I don't really understand how you would use the "New Method."

Re: How to spawn hinges, fixates, and springs

PostPosted: Tue Oct 27, 2009 4:20 am
by KarateBrot
yep. all the time i wondered why the hell this method is working or how it's working :wtf:

Re: How to spawn hinges, fixates, and springs

PostPosted: Thu Oct 29, 2009 6:14 pm
by RA2lover
looks like its a glitch exploitation.
when you use app.step, you do a scene minisave. app.undo deletes it, and those parameters'acessing is still marked last time.

not sure if algoryx will allow it to be official.

Re: How to spawn hinges, fixates, and springs

PostPosted: Thu Oct 29, 2009 6:23 pm
by standardtoaster
Well, if it might not always be there I won't add it.

Re: How to spawn hinges, fixates, and springs

PostPosted: Fri Oct 30, 2009 2:59 am
by Nait
Well, but can I spawn hinges without ID , like when i use hinge tool , it will read pos, look what object is there and connect it with lower one? :?:

Re: How to spawn hinges, fixates, and springs

PostPosted: Fri Oct 30, 2009 3:52 am
by standardtoaster
Sadly, no. You have to give the geom1 and geom0 otherwise you will get:
Code: Select all
!! ERROR: Constraint connected to unknown geometry


Edit: Added stuff about the console and whatnot.

Re: How to spawn hinges, fixates, and springs

PostPosted: Sun Nov 01, 2009 11:20 pm
by Altro
whats this "new method"?
link please

btw nice tut :thumbup:

Re: How to spawn hinges, fixates, and springs

PostPosted: Mon Nov 02, 2009 2:48 am
by RicH
How hard is it to search?
viewtopic.php?f=13&t=545

Re: How to spawn hinges, fixates, and springs

PostPosted: Sat Nov 07, 2009 1:54 am
by RA2lover
lol, if that would be true, attaching tracers to existing objects would be impossible.

Re: How to spawn hinges, fixates, and springs

PostPosted: Sat Nov 07, 2009 1:56 am
by standardtoaster
How so? Spawning a pen doesn't require a geomID. :|

Re: How to spawn hinges, fixates, and springs

PostPosted: Mon Nov 09, 2009 4:28 am
by Nait
Great discovery - if I have a spawner, it forgotts that old object has the same ID and works with the last one!

Re: How to spawn hinges, fixates, and springs

PostPosted: Mon Nov 09, 2009 4:41 am
by standardtoaster
Thanks! I never did understand why you can spawn multiple objects with the same ID. :|

Re: How to spawn hinges, fixates, and springs

PostPosted: Tue Nov 10, 2009 2:19 pm
by Nait
Never mind, I'm ve-e-e-e-e-ery clever ;)

Re: How to spawn hinges, fixates, and springs

PostPosted: Thu Apr 15, 2010 6:42 pm
by Rrobba
*Sorry for the bump*

Great tutorial! I especially like your use of diagrams. You've explained it pretty well because I never understood this, but now I do...

Re: How to spawn hinges, fixates, and springs

PostPosted: Sat May 29, 2010 8:14 pm
by davidz40
Can someone educated tell me if there are any negative consequences of spawning multiple objects with the same ID?

Re: How to spawn hinges, fixates, and springs

PostPosted: Tue Feb 01, 2011 3:59 pm
by FuzzyLogicBrain
Can i spawn a fixate with only 1 ID?

Re: How to spawn hinges, fixates, and springs

PostPosted: Fri Mar 04, 2011 6:39 am
by racergonemad
Nait wrote:Well, but can I spawn hinges without ID , like when i use hinge tool , it will read pos, look what object is there and connect it with lower one? :?:

Ive tried it. If you give the proper coordinates to 2 objects overlapping, a hinge will appear. At least on phun beta 5. I dont know about algodoo though.

Re: How to spawn hinges, fixates, and springs

PostPosted: Fri Mar 04, 2011 6:49 am
by racergonemad
Can someone tell me if their a way to spawn a hinge that has keyboard controls?
And whats up with the wierd motorSpeed property for spawned hinges. Like if I put scene.addHinge({motorSpeed := 10}) ill get a motor speed of 95 instead.
Great Tutorial BTW :clap:

Re: How to spawn hinges, fixates, and springs

PostPosted: Fri Mar 04, 2011 3:33 pm
by Someone Else
motorSpeed is probably in radians/second. Not rotations/minute.

And was the bump really, completely necessary?
Maybe... Very useful tutorial. :thumbup:

Re: How to spawn hinges, fixates, and springs

PostPosted: Sat Mar 12, 2011 5:03 pm
by Rideg
Someone Else wrote:...And was the bump really, completely necessary?...

As long as it is on topic.

Though it's a old tutorial it still works. Shame that new method was removed...