Spawning fixed objects

About advanced scenes, and the Thyme scripting language used in Algodoo.

Spawning fixed objects

Postby theclankinator » Sat Oct 10, 2015 7:23 pm

Is there a way I can spawn 2 squares and have them fixated together?

Like a shotgun ejecting a shotgun shell having yellow at the bottom fixated to a red shell

Thanks!
theclankinator
 
Posts: 7
Joined: Wed Jul 29, 2015 1:29 am

Re: Spawning fixed objects

Postby T'wind_ » Sat Oct 10, 2015 11:00 pm

You can use this code to create a fixjoint
Code: Select all
scene.addFixjoint({
    geom0 := ;
    geom0pos := ;
    geom1 := ;
    geom1pos := ;
    size := ;
})
User avatar
T'wind_
 
Posts: 86
Joined: Wed Jul 08, 2015 5:33 pm
Location: Western Europe

Re: Spawning fixed objects

Postby T'wind_ » Sat Oct 10, 2015 11:37 pm

This code will spawn something like a shotgun shell. It might not look like you wanted but if you upload your shotgun shell, I can make a script that spawns an exact copy of it.
Code: Select all
Scene.addBox({
        size := [2, 1];
        color := [0.76, 0, 0, 1];
        pos := [-1, 2.5];
        geomID := 1
    });
    Scene.addBox({
        size := [0.375, 1];
        color := [1, 1, 0.05, 1];
        pos := [-1.8125, 2.5];
        geomID := 0
    });
    Scene.addFixjoint({
        geom0 := 0;
        geom0pos := [0, 0];
        geom1 := 1;
        geom1pos := [-0.8125, 0];
        size := 0.2;
        color := [0, 0, 0, 0]
    })
User avatar
T'wind_
 
Posts: 86
Joined: Wed Jul 08, 2015 5:33 pm
Location: Western Europe

Re: Spawning fixed objects

Postby theclankinator » Sat Oct 10, 2015 11:43 pm

Thats perfect! Thank you! :D
theclankinator
 
Posts: 7
Joined: Wed Jul 29, 2015 1:29 am

Re: Spawning fixed objects

Postby theclankinator » Sat Oct 10, 2015 11:53 pm

T'wind_ wrote:This code will spawn something like a shotgun shell. It might not look like you wanted but if you upload your shotgun shell, I can make a script that spawns an exact copy of it.
Code: Select all
Scene.addBox({
        size := [2, 1];
        color := [0.76, 0, 0, 1];
        pos := [-1, 2.5];
        geomID := 1
    });
    Scene.addBox({
        size := [0.375, 1];
        color := [1, 1, 0.05, 1];
        pos := [-1.8125, 2.5];
        geomID := 0
    });
    Scene.addFixjoint({
        geom0 := 0;
        geom0pos := [0, 0];
        geom1 := 1;
        geom1pos := [-0.8125, 0];
        size := 0.2;
        color := [0, 0, 0, 0]
    })

Is there a way I can make the pos relative to a certain box?

So instead of the pos being [-1, 2.5], can I make it be pos := pos?

I played around with it a bit and the second geom just attached to the center of the first
theclankinator
 
Posts: 7
Joined: Wed Jul 29, 2015 1:29 am

Re: Spawning fixed objects

Postby T'wind_ » Sun Oct 11, 2015 11:04 am

Is there a way I can make the pos relative to a certain box?

So instead of the pos being [-1, 2.5], can I make it be pos := pos?


Yes, you can do it with pos := pos

I played around with it a bit and the second geom just attached to the center of the first


geom0pos is the position of the fixjoint relative to the center of geom0 and geom1pos is the position of the fixjoint relative to the center of geom1. So if you write geom0pos = [0, 0]; geom1pos = [0, 0] the center of the first box will be attached to the center of the second. If you write geom0pos = [-1, 0]; geom1pos = [1, 0] the right side of the first box will be attached to the left side of the second box. Note that the first box is geom1 and the second geom0.
User avatar
T'wind_
 
Posts: 86
Joined: Wed Jul 08, 2015 5:33 pm
Location: Western Europe


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 13 guests